clean up など
This commit is contained in:
@ -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) => {
|
||||
|
@ -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
|
||||
});
|
||||
|
Reference in New Issue
Block a user