lint
This commit is contained in:
parent
accdfd9b9e
commit
700614f3e6
|
@ -2,46 +2,42 @@ import { writable } from "svelte/store"
|
||||||
import { API } from "api"
|
import { API } from "api"
|
||||||
|
|
||||||
export function createPluginsStore() {
|
export function createPluginsStore() {
|
||||||
const { subscribe, set, update } = writable([])
|
const { subscribe, set, update } = writable([])
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
const plugins = await API.getPlugins()
|
const plugins = await API.getPlugins()
|
||||||
set(plugins)
|
set(plugins)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deletePlugin(pluginId, pluginRev) {
|
async function deletePlugin(pluginId, pluginRev) {
|
||||||
await API.deletePlugin(pluginId, pluginRev)
|
await API.deletePlugin(pluginId, pluginRev)
|
||||||
update(state => {
|
update(state => {
|
||||||
state = state.filter(
|
state = state.filter(existing => existing._id !== pluginId)
|
||||||
existing => existing._id !== pluginId
|
return state
|
||||||
)
|
})
|
||||||
return state
|
}
|
||||||
})
|
|
||||||
|
|
||||||
}
|
async function uploadPlugin(file, source) {
|
||||||
|
let data = new FormData()
|
||||||
async function uploadPlugin(file, source) {
|
data.append("file", file)
|
||||||
let data = new FormData()
|
let resp = await API.uploadPlugin(data, source)
|
||||||
data.append("file", file)
|
let newPlugin = resp.plugins[0]
|
||||||
let resp = await API.uploadPlugin(data, source)
|
update(state => {
|
||||||
let newPlugin = resp.plugins[0]
|
const currentIdx = state.findIndex(plugin => plugin._id === newPlugin._id)
|
||||||
update(state => {
|
if (currentIdx >= 0) {
|
||||||
const currentIdx = state.findIndex(plugin => plugin._id === newPlugin._id)
|
state.splice(currentIdx, 1, newPlugin)
|
||||||
if (currentIdx >= 0) {
|
} else {
|
||||||
state.splice(currentIdx, 1, newPlugin)
|
state.push(newPlugin)
|
||||||
} else {
|
}
|
||||||
state.push(newPlugin)
|
return state
|
||||||
}
|
})
|
||||||
return state
|
}
|
||||||
})
|
return {
|
||||||
|
subscribe,
|
||||||
}
|
load,
|
||||||
return {
|
deletePlugin,
|
||||||
subscribe,
|
uploadPlugin,
|
||||||
load,
|
}
|
||||||
deletePlugin,
|
|
||||||
uploadPlugin
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const plugins = createPluginsStore()
|
export const plugins = createPluginsStore()
|
||||||
|
|
|
@ -21,15 +21,14 @@ export const buildPluginEndpoints = API => ({
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a plugin.
|
* Deletes a plugin.
|
||||||
* @param pluginId the ID of the plugin to delete
|
* @param pluginId the ID of the plugin to delete
|
||||||
*
|
*
|
||||||
* * @param pluginId the revision of the plugin to delete
|
* * @param pluginId the revision of the plugin to delete
|
||||||
*/
|
*/
|
||||||
deletePlugin: async (pluginId, pluginRev) => {
|
deletePlugin: async (pluginId, pluginRev) => {
|
||||||
return await API.delete({
|
return await API.delete({
|
||||||
url: `/api/plugin/${pluginId}/${pluginRev}`,
|
url: `/api/plugin/${pluginId}/${pluginRev}`,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -52,7 +52,6 @@ export async function destroy(ctx: any) {
|
||||||
await db.remove(ctx.params.pluginId, ctx.params.pluginRev)
|
await db.remove(ctx.params.pluginId, ctx.params.pluginRev)
|
||||||
ctx.message = `Plugin ${ctx.params.pluginId} deleted.`
|
ctx.message = `Plugin ${ctx.params.pluginId} deleted.`
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function processPlugin(plugin: FileType, source?: string) {
|
export async function processPlugin(plugin: FileType, source?: string) {
|
||||||
|
|
|
@ -8,6 +8,10 @@ const router = new Router()
|
||||||
router
|
router
|
||||||
.post("/api/plugin/upload/:source", authorized(BUILDER), controller.upload)
|
.post("/api/plugin/upload/:source", authorized(BUILDER), controller.upload)
|
||||||
.get("/api/plugin", authorized(BUILDER), controller.fetch)
|
.get("/api/plugin", authorized(BUILDER), controller.fetch)
|
||||||
.delete("/api/plugin/:pluginId/:pluginRev", authorized(BUILDER), controller.destroy)
|
.delete(
|
||||||
|
"/api/plugin/:pluginId/:pluginRev",
|
||||||
|
authorized(BUILDER),
|
||||||
|
controller.destroy
|
||||||
|
)
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
|
|
Loading…
Reference in New Issue