mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
add hooks for tweaking how downloads happen (for grist-static) (#665)
This makes three main changes:
* Adds a hook to transform download links.
* Adds a hook to add an externally created ActiveDoc to a DocManager.
* Rejiggers XLSX export code so it can be used without streaming,
which is currently tricky in a browser. Regular usage with node
continues to use streaming.
With these changes, I have a POC in hand that updates grist-static
to support downloading CSVs, XLSXs, and .grist files.
This commit is contained in:
@@ -49,7 +49,7 @@ import {IDocWorkerMap} from "app/server/lib/DocWorkerMap";
|
||||
import {DownloadOptions, parseExportParameters} from "app/server/lib/Export";
|
||||
import {downloadCSV} from "app/server/lib/ExportCSV";
|
||||
import {collectTableSchemaInFrictionlessFormat} from "app/server/lib/ExportTableSchema";
|
||||
import {downloadXLSX} from "app/server/lib/ExportXLSX";
|
||||
import {streamXLSX} from "app/server/lib/ExportXLSX";
|
||||
import {expressWrap} from 'app/server/lib/expressWrap';
|
||||
import {filterDocumentInPlace} from "app/server/lib/filterUtils";
|
||||
import {googleAuthTokenMiddleware} from "app/server/lib/GoogleAuth";
|
||||
@@ -1911,3 +1911,14 @@ export interface WebhookSubscription {
|
||||
unsubscribeKey: string;
|
||||
webhookId: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts `activeDoc` to XLSX and sends the converted data through `res`.
|
||||
*/
|
||||
export async function downloadXLSX(activeDoc: ActiveDoc, req: Request,
|
||||
res: Response, options: DownloadOptions) {
|
||||
const {filename} = options;
|
||||
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
res.setHeader('Content-Disposition', contentDisposition(filename + '.xlsx'));
|
||||
return streamXLSX(activeDoc, req, res, options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user