clean up など

This commit is contained in:
syuilo
2021-03-20 15:42:02 +09:00
parent 73df95c42d
commit 9bb6dc52b8
5 changed files with 4 additions and 86 deletions

View File

@ -18,6 +18,7 @@ type executor<T extends IEndpointMeta> =
(params: Params<T>, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken | null, file?: any, cleanup?: Function) =>
Promise<T['res'] extends undefined ? Response : SchemaType<NonNullable<T['res']>>>;
// TODO: API関数に user まるごと渡すのではなくユーザーIDなどの最小限のプロパティだけ渡すようにしたい(キャッシュとか考えないでよくなるため)
export default function <T extends IEndpointMeta>(meta: T, cb: executor<T>)
: (params: any, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken | null, file?: any) => Promise<any> {
return (params: any, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken | null, file?: any) => {

View File

@ -1,6 +1,5 @@
import define from '../define';
import { RegistryItems, UserProfiles, Users } from '../../../models';
import { genId } from '../../../misc/gen-id';
import { Users } from '../../../models';
export const meta = {
desc: {
@ -23,28 +22,8 @@ export const meta = {
export default define(meta, async (ps, user, token) => {
const isSecure = token == null;
// TODO: そのうち消
const profile = await UserProfiles.findOneOrFail(user.id);
for (const [k, v] of Object.entries(profile.clientData)) {
await RegistryItems.insert({
id: genId(),
createdAt: new Date(),
updatedAt: new Date(),
userId: user.id,
domain: null,
scope: ['client', 'base'],
key: k,
value: v
});
}
await UserProfiles.createQueryBuilder().update()
.set({
clientData: {},
})
.where('userId = :id', { id: user.id })
.execute();
return await Users.pack(user, user, {
// ここで渡ってきている user はキャッシュされていて古い可能性もあるので id だけ渡
return await Users.pack(user.id, user, {
detail: true,
includeSecrets: isSecure
});