clean up など

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

View file

@ -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';

View file

@ -212,7 +212,6 @@ type Plugin = {
*/
export class ColdDeviceStorage {
public static default = {
themes: [] as Theme[], // TODO: そのうち消す
// TODO: テーマをアカウントに保存するようになったのにもかかわらず、以下のどのテーマを使うかという情報だけがブラウザ保存になっていて、アカウント切り替えたりログアウトしたときに不具合が発生するのでなんとかする
// テーマIDを保存するのではなく、テーマ自体を保存するようにすれば解決するかも
darkTheme: '8050783a-7f63-445a-b270-36d0f6ba1677',

View file

@ -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', []);
}

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
});