Fixed admin client
This commit is contained in:
@@ -2,7 +2,6 @@ import {ApiRouter, AuthorizeOptions, HttpDelete, HttpGet, HttpPatch, HttpPost, H
|
||||
import {BadRequestError, ValidationError} from "../../models/errors/index.js";
|
||||
import {albums} from "../../services/albums.js";
|
||||
import multer from "@koa/multer";
|
||||
import {instances} from "../../services/instances.js";
|
||||
|
||||
const upload = multer();
|
||||
class AlbumsApi extends ApiRouter {
|
||||
@@ -40,7 +39,8 @@ class AlbumsApi extends ApiRouter {
|
||||
/**
|
||||
* @param {KoaRequestContext} ctx
|
||||
*/
|
||||
async create({parameters: {instanceId}, body}) {
|
||||
async create(ctx) {
|
||||
const {parameters: {instanceId}, body} = ctx;
|
||||
return {
|
||||
data: await albums.createAlbum(instanceId, body)
|
||||
};
|
||||
@@ -49,7 +49,8 @@ class AlbumsApi extends ApiRouter {
|
||||
/**
|
||||
* @param {KoaRequestContext} ctx
|
||||
*/
|
||||
async update({parameters: {instanceId, albumId}, body: {name, description, sort}}) {
|
||||
async update(ctx) {
|
||||
let {parameters: {instanceId, albumId}, body: {name, description, sort}} = ctx;
|
||||
sort = sort || "auto";
|
||||
if (!["manual", "auto"].includes(sort)) {
|
||||
throw new ValidationError([{
|
||||
@@ -65,7 +66,8 @@ class AlbumsApi extends ApiRouter {
|
||||
/**
|
||||
* @param {KoaRequestContext} ctx
|
||||
*/
|
||||
async patch({parameters: {instanceId, albumId}, body}) {
|
||||
async patch(ctx) {
|
||||
const {parameters: {instanceId, albumId}, body} = ctx;
|
||||
return {
|
||||
data: await albums.patchAlbum(instanceId, albumId, body)
|
||||
};
|
||||
@@ -122,9 +124,10 @@ class AlbumsApi extends ApiRouter {
|
||||
/**
|
||||
* @param {KoaRequestContext} ctx
|
||||
*/
|
||||
async patchPhoto({parameters: {instanceId, albumId}, body}) {
|
||||
async patchPhoto(ctx) {
|
||||
const {parameters: {instanceId, albumId, photoId}, body} = ctx;
|
||||
return {
|
||||
data: await albums.patchPhoto(instanceId, albumId, parameters.photoId, body)
|
||||
data: await albums.patchPhoto(instanceId, albumId, photoId, body)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {ApiRouter, AuthorizeOptions, HttpGet, HttpPatch, HttpPost, HttpPut} from "../api-routing/index.js";
|
||||
import {ApiRouter, AuthorizeOptions, HttpDelete, HttpGet, HttpPatch, HttpPost, HttpPut} from "../api-routing/index.js";
|
||||
import {instances} from "../../services/instances.js";
|
||||
import {BadRequestError} from "../../models/errors/index.js";
|
||||
import {albums} from "../../services/albums.js";
|
||||
@@ -14,6 +14,7 @@ class InstancesApi extends ApiRouter {
|
||||
}));
|
||||
this.registerEndpoint(new HttpGet("/:instanceId", this.fetchInstance));
|
||||
this.registerEndpoint(new HttpPut("/:instanceId", this.updateInstance));
|
||||
this.registerEndpoint(new HttpDelete("/:instanceId", this.deleteInstance));
|
||||
this.registerEndpoint(new HttpPost("/:instanceId/upload-cover-photo", this.uploadPhoto, {
|
||||
middlewares: [upload.array('cover-photo')]
|
||||
}
|
||||
@@ -51,6 +52,14 @@ class InstancesApi extends ApiRouter {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {KoaRequestContext} ctx
|
||||
*/
|
||||
async deleteInstance({parameters, body}) {
|
||||
await instances.deleteInstance(parameters.instanceId);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {KoaRequestContext} ctx
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user