mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-07 05:59:02 +00:00
notion api upload file, registry integration tag
This commit is contained in:
parent
10a58ca18d
commit
a497618ea4
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user