Replace mock Google Sheet link with instant local CSV spreadsheet download generator

This commit is contained in:
2026-07-22 19:41:28 -04:00
parent 89b49be58d
commit 6ba84ba37e
3 changed files with 35 additions and 48 deletions
+22 -5
View File
@@ -616,13 +616,30 @@ app.post("/api/workspace/sheets/export", async (req, res) => {
});
}
// Fallback simulation if token not provided
const mockId = `sheet_${Date.now()}_${Math.random().toString(36).substring(2, 6)}`;
// Local CSV export generator when running without live Google OAuth access token
const headers = ["Company", "Role", "Platform", "Location", "Status", "Match Score (%)", "Applied Date", "Salary Range", "Notes"];
const rows = (applications || []).map((app: any) => [
`"${app.company || ''}"`,
`"${app.role || ''}"`,
`"${app.platform || 'Direct'}"`,
`"${app.location || ''}"`,
`"${app.status || 'APPLIED'}"`,
`"${app.matchScore || 85}"`,
`"${app.appliedAt || new Date().toISOString().split('T')[0]}"`,
`"${app.salaryRange || 'N/A'}"`,
`"${(app.notes || '').replace(/"/g, '""')}"`
]);
const csvContent = [headers.join(','), ...rows.map(r => r.join(','))].join('\n');
const base64Csv = Buffer.from(csvContent).toString('base64');
const downloadUrl = `data:text/csv;charset=utf-8;base64,${base64Csv}`;
res.json({
success: true,
spreadsheetId: mockId,
spreadsheetUrl: `https://docs.google.com/spreadsheets/d/${mockId}/edit`,
message: `Export prepared for Google Sheets (${(applications || []).length} applications).`
spreadsheetId: `local_csv_${Date.now()}`,
spreadsheetUrl: downloadUrl,
isLocalCsv: true,
message: `Exported ${(applications || []).length} applications to downloadable Spreadsheet (CSV format)!`
});
} catch (error: any) {
console.error("Google Sheets Export Error:", error);