Eliminate all mock fallbacks in Docs and Drive endpoints with real local file generators
This commit is contained in:
@@ -689,12 +689,18 @@ app.post("/api/workspace/docs/create", async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const mockId = `doc_${Date.now()}_${Math.random().toString(36).substring(2, 6)}`;
|
||||
// Local downloadable Document package generator when running without live Google OAuth access token
|
||||
const docTitle = title || `Tailored ${docType === 'coverLetter' ? 'Cover Letter' : 'Resume'}`;
|
||||
const htmlContent = `<!DOCTYPE html><html><head><meta charset="utf-8"><title>${docTitle}</title><style>body{font-family:Arial,sans-serif;line-height:1.6;padding:40px;max-width:800px;margin:0 auto;color:#111;}h1{border-bottom:2px solid #333;padding-bottom:10px;}pre{white-space:pre-wrap;font-family:inherit;}</style></head><body><h1>${docTitle}</h1><pre>${content || ''}</pre></body></html>`;
|
||||
const base64Doc = Buffer.from(htmlContent).toString('base64');
|
||||
const downloadUrl = `data:text/html;charset=utf-8;base64,${base64Doc}`;
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
documentId: mockId,
|
||||
documentUrl: `https://docs.google.com/document/d/${mockId}/edit`,
|
||||
message: `Google Doc prepared for ${title}`
|
||||
documentId: `local_doc_${Date.now()}`,
|
||||
documentUrl: downloadUrl,
|
||||
isLocalDoc: true,
|
||||
message: `Created downloadable Document package for ${docTitle}!`
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error("Google Docs Creation Error:", error);
|
||||
@@ -734,12 +740,17 @@ app.post("/api/workspace/drive/upload", async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const mockId = `drive_${Date.now()}_${Math.random().toString(36).substring(2, 6)}`;
|
||||
// Local downloadable artifact file generator when running without live Google OAuth access token
|
||||
const safeFileName = fileName || `Job_Artifact_${Date.now()}.txt`;
|
||||
const base64File = Buffer.from(fileContent || '').toString('base64');
|
||||
const downloadUrl = `data:${mimeType || 'text/plain'};base64,${base64File}`;
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
fileId: mockId,
|
||||
driveUrl: `https://drive.google.com/file/d/${mockId}/view`,
|
||||
message: `File saved to Google Drive workspace folder.`
|
||||
fileId: `local_file_${Date.now()}`,
|
||||
driveUrl: downloadUrl,
|
||||
isLocalFile: true,
|
||||
message: `Saved ${safeFileName} to local workspace storage!`
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error("Google Drive Upload Error:", error);
|
||||
|
||||
@@ -211,6 +211,18 @@ export const GoogleWorkspaceHub: React.FC<GoogleWorkspaceHubProps> = ({
|
||||
accessToken || undefined
|
||||
);
|
||||
|
||||
if (res.isLocalDoc && res.documentUrl) {
|
||||
const link = document.createElement('a');
|
||||
link.href = res.documentUrl;
|
||||
link.download = `${docTitle.replace(/[^a-z0-9_-]/gi, '_')}.html`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
showToast('✓ Document compiled & downloaded to local file!');
|
||||
} else {
|
||||
showToast('Tailored document exported to Google Docs!');
|
||||
}
|
||||
|
||||
setGeneratedDocs(prev => [
|
||||
{
|
||||
title: docTitle,
|
||||
@@ -222,7 +234,6 @@ export const GoogleWorkspaceHub: React.FC<GoogleWorkspaceHubProps> = ({
|
||||
|
||||
setDocTitle('');
|
||||
setDocContent('');
|
||||
showToast('Tailored document exported to Google Docs!');
|
||||
} catch (err: any) {
|
||||
showToast(`Google Docs: ${err.message}`);
|
||||
} finally {
|
||||
@@ -256,7 +267,18 @@ export const GoogleWorkspaceHub: React.FC<GoogleWorkspaceHubProps> = ({
|
||||
accessToken || undefined
|
||||
);
|
||||
|
||||
showToast('Saved file to Google Drive folder!');
|
||||
if (res.isLocalFile && res.driveUrl) {
|
||||
const link = document.createElement('a');
|
||||
link.href = res.driveUrl;
|
||||
link.download = uploadFileName;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
showToast(`✓ ${uploadFileName} saved & downloaded to local workspace!`);
|
||||
} else {
|
||||
showToast(`✓ ${uploadFileName} uploaded to Google Drive!`);
|
||||
}
|
||||
|
||||
setDriveFiles(prev => [
|
||||
{
|
||||
id: res.fileId,
|
||||
|
||||
Reference in New Issue
Block a user