diff --git a/api/notion.mjs b/api/notion.mjs index fbcf8e7..cd9a565 100644 --- a/api/notion.mjs +++ b/api/notion.mjs @@ -304,6 +304,48 @@ export const create = async ( return json.errorId ? json : recordID; }; +/** + * unofficial content api: upload a file to notion's aws servers + * (requires user to be signed in or content to be public). + * TEST THIS THOROUGHLY. misuse can corrupt a record, leading the notion client + * to be unable to parse and render content properly and throw errors. + * why not use the official api? + * 1. cors blocking prevents use on the client + * 2. the majority of blocks are still 'unsupported' + * @param {File} file - the file to upload + * @param {object} [pointer] - where the file should be accessible from + * @param {string} [pointer.pageID] - uuidv4 page id + * @param {string} [pointer.spaceID] - uuidv4 space id + * @returns {string|object} error object or the url of the uploaded file + */ +export const upload = async (file, { pageID = getPageID(), spaceID = getSpaceID() } = {}) => { + spaceID = standardiseUUID(await spaceID); + pageID = standardiseUUID(pageID); + const json = await fs.getJSON('https://www.notion.so/api/v3/getUploadFileUrl', { + method: 'POST', + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + bucket: 'secure', + name: file.name, + contentType: file.type, + record: { + table: 'block', + id: pageID, + spaceId: spaceID, + }, + }), + }); + if (json.errorId) return json; + fetch(json.signedPutUrl, { + method: 'PUT', + headers: { 'content-type': file.type }, + body: file, + }); + return json.url; +}; + /** * redirect through notion to a resource's signed aws url for display outside of notion * (requires user to be signed in or content to be public) diff --git a/api/registry-validation.mjs b/api/registry-validation.mjs index 76f6450..47a8d3f 100644 --- a/api/registry-validation.mjs +++ b/api/registry-validation.mjs @@ -50,11 +50,11 @@ const validateEnvironments = async (mod) => { validateTags = async (mod) => { const isArray = await check(mod, 'tags', mod.tags, 'array'); if (!isArray) return false; - const categoryTags = ['core', 'extension', 'theme'], + const categoryTags = ['core', 'extension', 'theme', 'integration'], containsCategory = mod.tags.filter((tag) => categoryTags.includes(tag)).length; if (!containsCategory) { mod._err( - `invalid tags (must contain at least one of 'core', 'extension', or 'theme'): + `invalid tags (must contain at least one of 'core', 'extension', 'theme' or 'integration'): ${JSON.stringify(mod.tags)}` ); return false;