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({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
documentId: mockId,
|
documentId: `local_doc_${Date.now()}`,
|
||||||
documentUrl: `https://docs.google.com/document/d/${mockId}/edit`,
|
documentUrl: downloadUrl,
|
||||||
message: `Google Doc prepared for ${title}`
|
isLocalDoc: true,
|
||||||
|
message: `Created downloadable Document package for ${docTitle}!`
|
||||||
});
|
});
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("Google Docs Creation Error:", error);
|
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({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
fileId: mockId,
|
fileId: `local_file_${Date.now()}`,
|
||||||
driveUrl: `https://drive.google.com/file/d/${mockId}/view`,
|
driveUrl: downloadUrl,
|
||||||
message: `File saved to Google Drive workspace folder.`
|
isLocalFile: true,
|
||||||
|
message: `Saved ${safeFileName} to local workspace storage!`
|
||||||
});
|
});
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("Google Drive Upload Error:", error);
|
console.error("Google Drive Upload Error:", error);
|
||||||
|
|||||||
@@ -211,6 +211,18 @@ export const GoogleWorkspaceHub: React.FC<GoogleWorkspaceHubProps> = ({
|
|||||||
accessToken || undefined
|
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 => [
|
setGeneratedDocs(prev => [
|
||||||
{
|
{
|
||||||
title: docTitle,
|
title: docTitle,
|
||||||
@@ -222,7 +234,6 @@ export const GoogleWorkspaceHub: React.FC<GoogleWorkspaceHubProps> = ({
|
|||||||
|
|
||||||
setDocTitle('');
|
setDocTitle('');
|
||||||
setDocContent('');
|
setDocContent('');
|
||||||
showToast('Tailored document exported to Google Docs!');
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showToast(`Google Docs: ${err.message}`);
|
showToast(`Google Docs: ${err.message}`);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -256,7 +267,18 @@ export const GoogleWorkspaceHub: React.FC<GoogleWorkspaceHubProps> = ({
|
|||||||
accessToken || undefined
|
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 => [
|
setDriveFiles(prev => [
|
||||||
{
|
{
|
||||||
id: res.fileId,
|
id: res.fileId,
|
||||||
|
|||||||
Reference in New Issue
Block a user