Fixed 267U.pre2
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import define from "../../define.js";
|
||||
import { Apps } from "../../../../models/index.js";
|
||||
import { genId } from "../../../../misc/gen-id.js";
|
||||
import { unique } from "../../../../prelude/array.js";
|
||||
import { secureRndstr } from "../../../../misc/secure-rndstr.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"app"
|
||||
],
|
||||
requireCredential: false,
|
||||
res: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
ref: "App"
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
name: {
|
||||
type: "string"
|
||||
},
|
||||
description: {
|
||||
type: "string"
|
||||
},
|
||||
permission: {
|
||||
type: "array",
|
||||
uniqueItems: true,
|
||||
items: {
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
callbackUrl: {
|
||||
type: "string",
|
||||
nullable: true
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"name",
|
||||
"description",
|
||||
"permission"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
if (user?.movedToUri != null) return await Apps.pack("", null, {
|
||||
detail: true,
|
||||
includeSecret: true
|
||||
});
|
||||
// Generate secret
|
||||
const secret = secureRndstr(32);
|
||||
// for backward compatibility
|
||||
const permission = unique(ps.permission.map((v)=>v.replace(/^(.+)(\/|-)(read|write)$/, "$3:$1")));
|
||||
// Create account
|
||||
const app = await Apps.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
userId: user ? user.id : null,
|
||||
name: ps.name,
|
||||
description: ps.description,
|
||||
permission,
|
||||
callbackUrl: ps.callbackUrl,
|
||||
secret: secret
|
||||
}).then((x)=>Apps.findOneByOrFail(x.identifiers[0]));
|
||||
return await Apps.pack(app, null, {
|
||||
detail: true,
|
||||
includeSecret: true
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
import define from "../../define.js";
|
||||
import { ApiError } from "../../error.js";
|
||||
import { Apps } from "../../../../models/index.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"app"
|
||||
],
|
||||
errors: {
|
||||
noSuchApp: {
|
||||
message: "No such app.",
|
||||
code: "NO_SUCH_APP",
|
||||
id: "dce83913-2dc6-4093-8a7b-71dbb11718a3"
|
||||
}
|
||||
},
|
||||
res: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
ref: "App"
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
appId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"appId"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user, token)=>{
|
||||
const isSecure = user != null && token == null;
|
||||
// Lookup app
|
||||
const ap = await Apps.findOneBy({
|
||||
id: ps.appId
|
||||
});
|
||||
if (ap == null) {
|
||||
throw new ApiError(meta.errors.noSuchApp);
|
||||
}
|
||||
return await Apps.pack(ap, user, {
|
||||
detail: true,
|
||||
includeSecret: isSecure && ap.userId === user.id
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user