API Reference¶
Complete API documentation for Skigk Søkeapp.
AuthService¶
Manages Google OAuth 2.0 authentication and user session.
Methods¶
initializeOAuth()¶
Initializes Google OAuth with your credentials.
authService.initializeOAuth();
Parameters: None
Returns: Promise<void>
login()¶
Redirects user to Google OAuth consent screen.
authService.login();
Parameters: None
Returns: Promise<User | null>
Example:
const user = await authService.login();
if (user) {
console.log(`Logged in as ${user.name}`);
}
logout()¶
Logs out current user and revokes OAuth token.
authService.logout();
Parameters: None
Returns: Promise<void>
getCurrentUser()¶
Gets the currently logged-in user.
const user = authService.getCurrentUser();
Returns: User | null
Properties:
- id: string - User's Google ID
- name: string - User's display name
- email: string - User's email address
DriveService¶
Searches and retrieves content from Google Drive and Shared Drives.
Methods¶
searchFiles(query: string)¶
Searches all Drives for files matching the query.
driveService.searchFiles('quarterly report').subscribe(
files => console.log(files),
error => console.error(error)
);
Parameters:
- query: string - Search text (supports Google Drive search operators)
Returns: Observable<DriveFile[]>
Search Operators:
name:"filename" # Exact filename
fullText:"text" # Text in file content
owner:"email@domain.com" # Files owned by user
modifiedDate>2026-01-01 # Modified after date
mimeType:... # File type
Example:
// Search all Sheets files
driveService.searchFiles('mimeType:"application/vnd.google-apps.spreadsheet"')
// Search recent documents
driveService.searchFiles('modifiedDate>2026-01-01')
getFileContent(fileId: string, mimeType: string)¶
Retrieves the content of a file.
driveService.getFileContent('file-123', 'text/plain').subscribe(
content => console.log(content)
);
Parameters:
- fileId: string - Google Drive file ID
- mimeType: string - File's MIME type
Returns: Observable<string>
Supported MIME Types:
- application/vnd.google-apps.document - Google Docs → converted to text
- application/vnd.google-apps.spreadsheet - Google Sheets → CSV format
- text/plain - Plain text files
- application/pdf - PDF files
- text/html - HTML files
getFilePreviewLink(fileId: string)¶
Returns a link to preview the file in Google Drive.
const link = driveService.getFilePreviewLink('file-123');
// Opens: https://drive.google.com/file/d/file-123/view
Parameters:
- fileId: string - Google Drive file ID
Returns: string - Full preview URL
GeminiService¶
Generates AI-powered summaries of file content.
Methods¶
summarizeContent(fileName: string, content: string)¶
Generates a summary of file content using Gemini AI.
geminiService.summarizeContent('report.docx', 'File content...').subscribe(
summary => console.log(summary)
);
Parameters:
- fileName: string - Name of the file (for context)
- content: string - The file content to summarize
Returns: Observable<string> - AI-generated summary
Prompt Template (Norwegian):
Lag en kort oppsummering (3-5 setninger) av følgende dokument:
[Filename]: {fileName}
[Innhold]: {content}
Oppsummeringen skal være:
- Kortfattet og relevant
- Skrevet på norsk
- Fokusert på nøkkelpunkter
isAvailable()¶
Checks if Gemini API is configured.
if (geminiService.isAvailable()) {
// Show "Get Summary" button
}
Returns: boolean
DriveFile Model¶
Represents a searchable file from Google Drive.
interface DriveFile {
id: string; // Google Drive file ID
name: string; // File name
mimeType: string; // File MIME type
owners: Array<{
displayName: string; // Owner's name
emailAddress?: string; // Owner's email
}>;
modifiedTime: string; // ISO date string
webViewLink: string; // Link to open in Drive
size?: number; // File size in bytes
starred?: boolean; // Is file starred
}
User Model¶
Represents an authenticated user.
interface User {
id: string; // User's Google ID
name: string; // User's display name
email: string; // User's email address
picture?: string; // Profile picture URL
}
Configuration¶
Environment Variables¶
.env.local
# Required for Google OAuth
VITE_GOOGLE_CLIENT_ID=YOUR_CLIENT_ID.apps.googleusercontent.com
# Required for Gemini summaries (optional)
VITE_GEMINI_API_KEY=YOUR_API_KEY
# Optional: API endpoints
VITE_DRIVE_API_VERSION=v3
VITE_GEMINI_MODEL=gemini-2.5-flash
src/config.ts¶
export const GOOGLE_SCOPES = [
'drive.readonly',
'userinfo.profile',
'spreadsheets.readonly'
];
export const SEARCH_DEBOUNCE_MS = 300;
export const FILE_PAGE_SIZE = 20;
export const GEMINI_MAX_TOKENS = 500;
Error Handling¶
AuthService Errors¶
// Handles 401 (Unauthorized)
// Automatically logs out user
// Clears tokens from storage
DriveService Errors¶
// Handles 403 (Forbidden)
// Returns empty results instead of error
// Logs error to console
// Handles 429 (Rate Limited)
// Automatic retry with exponential backoff
GeminiService Errors¶
// Handles API key errors
// Gracefully falls back to: "Could not generate summary"
// Does not block search functionality
Rate Limits¶
Google Drive API¶
- Queries per user per 100 seconds: 1,000
- Queries per project per 100 seconds: 10,000
Google Gemini API¶
- Free tier: 60 requests/minute
- Paid: 1,000+ requests/minute (depends on quota)
Examples¶
Complete Search Example¶
import { Component } from '@angular/core';
import { DriveService } from './services/drive.service';
@Component({
selector: 'app-search',
template: `
<input [(ngModel)]="query" (change)="search()" />
<div *ngFor="let file of files">
<h3>{{ file.name }}</h3>
<p>{{ file.owners[0].displayName }}</p>
</div>
`
})
export class SearchComponent {
query = '';
files: any[] = [];
constructor(private driveService: DriveService) {}
search() {
this.driveService.searchFiles(this.query).subscribe(
files => this.files = files,
error => console.error('Search failed', error)
);
}
}
Summarization Example¶
import { Component } from '@angular/core';
import { GeminiService } from './services/gemini.service';
@Component({
selector: 'app-summary',
template: `
<button (click)="generateSummary()">Get Summary</button>
<p>{{ summary }}</p>
`
})
export class SummaryComponent {
summary = '';
constructor(private geminiService: GeminiService) {}
generateSummary() {
const content = 'File content here...';
this.geminiService.summarizeContent('file.pdf', content).subscribe(
summary => this.summary = summary
);
}
}
Troubleshooting API Issues¶
Search returns 401 Unauthorized:
- User's OAuth token may have expired
- Call authService.logout() then authService.login()
Gemini API returns quota exceeded: - Check Google Cloud quota limits - Upgrade to paid tier if needed
DriveService returns empty results: - User may not be member of Shared Drive - File permissions may be restricted
Last Updated: January 2026 | API Version: 1.0