-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathroutes.mjs
31 lines (29 loc) · 1.69 KB
/
routes.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Collections, must be plural (http://apistylebook.com/design/guidelines/google-api-design-guide)
export const pattern = '(/regions/:region)?(/mods/:mods)?(/secrets/:secretids)?(/cells/:cellids)?(/notebooks/:namespace/:notebook)(/deployments/:deploy|/deploys/:deploy)?(/mods/:mods)?(/secrets/:secretids)?(/cells/:cellids)?(/:user(*))?';
export function decode(req) {
let query = ''
let secretKeys = req.params.secretids ? (req.params.secretids).split(",").map(decodeURIComponent): [];
let userURL = "/" + (req.params.user || '');
let baseURL = req.params.user ?
req.url.substring(0, req.url.length - userURL.length)
: req.url
if (req.params.cellids) {
query = '?' + req.params.cellids.split(",").map(name => `cell=${name}`).join("&")
}
const notebookURL = (req.params.namespace == 'd' || req.params.namespace == 'thumbnail'
? `https://observablehq.com/embed/${req.params.notebook}${query}`
: `https://observablehq.com/embed/${req.params.namespace}/${req.params.notebook}${query}`);
return {
shard: `${req.params.namespace}/${req.params.notebook}`,
notebookURL: notebookURL,
baseURL: baseURL,
userURL: userURL,
notebook: req.params.notebook,
secretKeys: secretKeys,
deploy: req.params.deploy || 'default',
hasMods: req.params.mods ? true : false,
isExternal: req.params.mods ? req.params.mods.includes("X") : undefined, // Cannot be called by other serverless cels
isTerminal: req.params.mods ? req.params.mods.includes("T") : undefined, // Cannot call other serverless cells
isOrchestrator: req.params.mods ? req.params.mods.includes("O") : undefined
};
}