apply blacklist also on plugin download
Massimo Melina committed
Sep 28, 2023 at 00:22 UTC
30ee51948fbe6c697383a3d770f4d0aec4b46867
2 files changed
+10
-9
src/api.plugins.ts
+2
-4
@@ -129,10 +129,8 @@ const apis: ApiHandlers = {
129
130
async download_plugin({ id, branch }) {
131
await checkDependencies(await readOnlinePlugin(id, branch))
132
- const res = await downloadPlugin(id, { branch })
133
- if (typeof res !== 'string')
134
- return res
135
- return (await waitFor(() => getPluginInfo(res), { timeout: 5000 }))
132
+ const folder = await downloadPlugin(id, { branch })
133
+ return (await waitFor(() => getPluginInfo(folder), { timeout: 5000 }))
134
|| new ApiError(HTTP_SERVER_ERROR)
135
},
136
src/github.ts
+8
-5
@@ -16,7 +16,7 @@ import {
16
HFS_REPO,
17
HFS_REPO_BRANCH,
18
HTTP_BAD_REQUEST,
19
- HTTP_CONFLICT,
19
+ HTTP_CONFLICT, HTTP_FORBIDDEN,
20
HTTP_NOT_ACCEPTABLE,
21
HTTP_SERVER_ERROR
22
} from './const'
@@ -47,18 +47,21 @@ export async function downloadPlugin(repo: Repo, { branch='', overwrite=false }=
47
if (typeof repo !== 'string')
48
repo = repo.main
49
if (downloading[repo])
50
- return new ApiError(HTTP_CONFLICT, "already downloading")
50
+ throw new ApiError(HTTP_CONFLICT, "already downloading")
51
+ const projectInfo = await getProjectInfo()
52
+ if (projectInfo?.plugins_blacklist?.includes(repo))
53
+ throw new ApiError(HTTP_FORBIDDEN, "blacklisted")
54
console.log('downloading plugin', repo)
55
downloadProgress(repo, true)
56
try {
57
if (repo.includes('//')) { // custom repo
58
const pl = findPluginByRepo(repo)
59
if (!pl)
57
- return new ApiError(HTTP_BAD_REQUEST, "bad repo")
60
+ throw new ApiError(HTTP_BAD_REQUEST, "bad repo")
61
const customRepo = ((pl as any).getData?.() || pl).repo
62
let url = customRepo?.zip
63
if (!url)
61
- return new ApiError(HTTP_SERVER_ERROR, "bad plugin")
64
+ throw new ApiError(HTTP_SERVER_ERROR, "bad plugin")
65
if (!url.includes('//'))
66
url = customRepo.web + url
67
return await go(url, pl?.id, customRepo.zipRoot ?? DIST_ROOT)
@@ -66,7 +69,7 @@ export async function downloadPlugin(repo: Repo, { branch='', overwrite=false }=
69
branch ||= await getGithubDefaultBranch(repo)
70
const short = repo.split('/')[1] // second part, repo without the owner
71
if (!short)
69
- return new ApiError(HTTP_BAD_REQUEST, "bad repo")
72
+ throw new ApiError(HTTP_BAD_REQUEST, "bad repo")
73
const folder = overwrite ? _.findKey(getFolder2repo(), x => x===repo)! // use existing folder
74
: getFolder2repo().hasOwnProperty(short) ? repo.replace('/','-') // longer form only if another plugin is using short form, to avoid overwriting
75
: short