diff --git a/server.ts b/server.ts index 01cac64..0f3b5e3 100644 --- a/server.ts +++ b/server.ts @@ -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 = `${docTitle}

${docTitle}

${content || ''}
`; + 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); diff --git a/src/components/GoogleWorkspaceHub.tsx b/src/components/GoogleWorkspaceHub.tsx index fa0bf53..328a7f8 100644 --- a/src/components/GoogleWorkspaceHub.tsx +++ b/src/components/GoogleWorkspaceHub.tsx @@ -211,6 +211,18 @@ export const GoogleWorkspaceHub: React.FC = ({ 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 = ({ 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 = ({ 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,