From 9bb6dc52b855dcebd0c0493240d6282ba21810c2 Mon Sep 17 00:00:00 2001
From: syuilo <Syuilotan@yahoo.co.jp>
Date: Sat, 20 Mar 2021 15:42:02 +0900
Subject: [PATCH] =?UTF-8?q?clean=20up=20=E3=81=AA=E3=81=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/client/init.ts            | 34 ----------------------------------
 src/client/store.ts           |  1 -
 src/client/theme-store.ts     | 27 ---------------------------
 src/server/api/define.ts      |  1 +
 src/server/api/endpoints/i.ts | 27 +++------------------------
 5 files changed, 4 insertions(+), 86 deletions(-)

diff --git a/src/client/init.ts b/src/client/init.ts
index 1c44e7f23..2a2b6a2f8 100644
--- a/src/client/init.ts
+++ b/src/client/init.ts
@@ -4,40 +4,6 @@
 
 import '@/style.scss';
 
-// TODO: そのうち消す
-if (localStorage.getItem('vuex') != null) {
-	const vuex = JSON.parse(localStorage.getItem('vuex'));
-
-	localStorage.setItem('account', JSON.stringify({
-		...vuex.i,
-		token: localStorage.getItem('i')
-	}));
-	localStorage.setItem('accounts', JSON.stringify(vuex.device.accounts));
-	localStorage.setItem('miux:themes', JSON.stringify(vuex.device.themes));
-
-	if (vuex.device.userData) {
-		for (const [k, v] of 	Object.entries(vuex.device.userData)) {
-			localStorage.setItem('pizzax::base::' + k, JSON.stringify({
-				widgets: v.widgets
-			}));
-
-			if (v.deck) {
-				localStorage.setItem('pizzax::deck::' + k, JSON.stringify({
-					columns: v.deck.columns,
-					layout: v.deck.layout,
-				}));
-			}
-		}
-	}
-
-	localStorage.setItem('vuex-old', JSON.stringify(vuex));
-	localStorage.removeItem('vuex');
-	localStorage.removeItem('i');
-	localStorage.removeItem('locale');
-
-	location.reload();
-}
-
 import * as Sentry from '@sentry/browser';
 import { Integrations } from '@sentry/tracing';
 import { createApp, watch } from 'vue';
diff --git a/src/client/store.ts b/src/client/store.ts
index 14924dadd..e6fdd12f1 100644
--- a/src/client/store.ts
+++ b/src/client/store.ts
@@ -212,7 +212,6 @@ type Plugin = {
  */
 export class ColdDeviceStorage {
 	public static default = {
-		themes: [] as Theme[], // TODO: そのうち消す
 		// TODO: テーマをアカウントに保存するようになったのにもかかわらず、以下のどのテーマを使うかという情報だけがブラウザ保存になっていて、アカウント切り替えたりログアウトしたときに不具合が発生するのでなんとかする
 		// テーマIDを保存するのではなく、テーマ自体を保存するようにすれば解決するかも
 		darkTheme: '8050783a-7f63-445a-b270-36d0f6ba1677',
diff --git a/src/client/theme-store.ts b/src/client/theme-store.ts
index 5e440efbf..8e21af70f 100644
--- a/src/client/theme-store.ts
+++ b/src/client/theme-store.ts
@@ -33,30 +33,3 @@ export async function removeTheme(theme: Theme): Promise<void> {
 	await api('i/registry/set', { scope: ['client'], key: 'themes', value: themes });
 	localStorage.setItem(lsCacheKey, JSON.stringify(themes));
 }
-
-// TODO: そのうち消す
-if (ColdDeviceStorage.get('themes').length > 0) {
-	const lsThemes = ColdDeviceStorage.get('themes');
-	let registryThemes;
-	try {
-		registryThemes = await api('i/registry/get', { scope: ['client'], key: 'themes' });
-	} catch (e) {
-		if (e.code === 'NO_SUCH_KEY') {
-			registryThemes = [];
-		} else {
-			throw e;
-		}
-	}
-	const themes = [] as Theme[];
-	for (const theme of lsThemes) {
-		if (themes.some(x => x.id === theme.id)) continue;
-		themes.push(theme);
-	}
-	for (const theme of registryThemes) {
-		if (themes.some(x => x.id === theme.id)) continue;
-		themes.push(theme);
-	}
-	await api('i/registry/set', { scope: ['client'], key: 'themes', value: themes });
-	localStorage.setItem(lsCacheKey, JSON.stringify(themes));
-	ColdDeviceStorage.set('themes', []);
-}
diff --git a/src/server/api/define.ts b/src/server/api/define.ts
index 1c7ee2647..4e59357c1 100644
--- a/src/server/api/define.ts
+++ b/src/server/api/define.ts
@@ -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) => {
diff --git a/src/server/api/endpoints/i.ts b/src/server/api/endpoints/i.ts
index e5b65e093..87f6ae778 100644
--- a/src/server/api/endpoints/i.ts
+++ b/src/server/api/endpoints/i.ts
@@ -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
 	});