mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
dd8d2e18f5
Summary: With this, a custom widget can render an attachment by doing: ``` const tokenInfo = await grist.docApi.getAccessToken({readOnly: true}); const img = document.getElementById('the_image'); const id = record.C[0]; // get an id of an attachment const src = `${tokenInfo.baseUrl}/attachments/${id}/download?auth=${tokenInfo.token}`; img.setAttribute('src', src) ``` The access token expires after a few mins, so if a user right-clicks on an image to save it, they may get access denied unless they refresh the page. A little awkward, but s3 pre-authorized links behave similarly and it generally isn't a deal-breaker. Test Plan: added tests Reviewers: dsagal Reviewed By: dsagal Subscribers: dsagal Differential Revision: https://phab.getgrist.com/D3488
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
/**
|
|
* This module was automatically generated by `ts-interface-builder`
|
|
*/
|
|
import * as t from "ts-interface-checker";
|
|
// tslint:disable:object-literal-key-quotes
|
|
|
|
export const ComponentKind = t.union(t.lit("safeBrowser"), t.lit("safePython"), t.lit("unsafeNode"));
|
|
|
|
export const GristAPI = t.iface([], {
|
|
"render": t.func("number", t.param("path", "string"), t.param("target", "RenderTarget"), t.param("options", "RenderOptions", true)),
|
|
"dispose": t.func("void", t.param("procId", "number")),
|
|
"subscribe": t.func("void", t.param("tableId", "string")),
|
|
"unsubscribe": t.func("void", t.param("tableId", "string")),
|
|
});
|
|
|
|
export const GristDocAPI = t.iface([], {
|
|
"getDocName": t.func("string"),
|
|
"listTables": t.func(t.array("string")),
|
|
"fetchTable": t.func("any", t.param("tableId", "string")),
|
|
"applyUserActions": t.func("any", t.param("actions", t.array(t.array("any"))), t.param("options", "any", true)),
|
|
"getAccessToken": t.func("AccessTokenResult", t.param("options", "AccessTokenOptions")),
|
|
});
|
|
|
|
export const GristView = t.iface([], {
|
|
"fetchSelectedTable": t.func("any"),
|
|
"fetchSelectedRecord": t.func("any", t.param("rowId", "number")),
|
|
"allowSelectBy": t.func("void"),
|
|
"setSelectedRows": t.func("void", t.param("rowIds", t.array("number"))),
|
|
});
|
|
|
|
export const AccessTokenOptions = t.iface([], {
|
|
"readOnly": t.opt("boolean"),
|
|
});
|
|
|
|
export const AccessTokenResult = t.iface([], {
|
|
"token": "string",
|
|
"baseUrl": "string",
|
|
"ttlMsecs": "number",
|
|
});
|
|
|
|
const exportedTypeSuite: t.ITypeSuite = {
|
|
ComponentKind,
|
|
GristAPI,
|
|
GristDocAPI,
|
|
GristView,
|
|
AccessTokenOptions,
|
|
AccessTokenResult,
|
|
};
|
|
export default exportedTypeSuite;
|