Chg: exactOptionalPropertyTypesをfalseに変更 / Chg(Security): トークンが不正な場合のエラーを全てtoken_invalidに変更 / New: channelテーブル・リポジトリ / Chg: configテーブルのvalueをstringに / Chg: configテーブルのlengthを4096に / New: messageテーブル / Chg: 安全のためuserテーブルのOptionalPropsにidを追加 / New: channel/createエンドポイント / New: channel/listエンドポイント / New: channel/editエンドポイント / Enhance: primary/signupエンドポイントの重複エラーの実装で末尾カンマなどの改善 / Chg: setup/initializationのdescriptionに最大文字数4096を制定 / Chg: serverInfoをdefault exportからexportに変更 / New: フロントエンドでmeを読み込み / New: フロントエンドでchannelを読み込み / New: client.tsでトークンがある場合はトークンを指定 / Chg: clientをrefに / Del: IndexedDBからserverテーブルを削除 / Fix: Dexieのclassに命名 / Feat: フロントエンドでのサインインページ / Fix: L.jsで任意のbodyがあるエンドポイントが定義できない問題を修正 / Del: L.jsのserver-infoでの不要なimportを削除 / Fix: L.jsでトークンのエラーを追加 / Fix: L.jsのUserSchemaにlastUsedAtを追加
This commit is contained in:
@@ -1,11 +1,57 @@
|
||||
import client from "@/lib/client";
|
||||
import client, { initClient } from "@/lib/client";
|
||||
import type ApiMap from "lynqchat-js/1.0.0-alpha.0/map";
|
||||
import { ref } from "vue";
|
||||
/*
|
||||
[TODO]
|
||||
キャッシュの類を全部account.tsに詰め込むのをやめる
|
||||
*/
|
||||
|
||||
let serverInfo = ref<ApiMap["server-info"]["response"]>(await client.request("server-info"));
|
||||
await initClient();
|
||||
|
||||
export let serverInfo = ref<ApiMap["server-info"]["response"]>(await client.value.request("server-info"));
|
||||
export let account = ref<ApiMap["me"]["response"]>(await client.value.request("me"));
|
||||
|
||||
export let channels = ref<Extract<ApiMap["channel/list"]["response"], { channels: any }>["channels"]>([]);
|
||||
export let lastLoadedChannel = ref<string>();
|
||||
|
||||
export const reloadServerInfo = async () => {
|
||||
serverInfo.value = await client.request("server-info");
|
||||
serverInfo.value = await client.value.request("server-info");
|
||||
}
|
||||
|
||||
export default serverInfo;
|
||||
export const reloadAccount = async () => {
|
||||
await initClient();
|
||||
|
||||
account.value = await client.value.request("me");
|
||||
}
|
||||
|
||||
export const initChannels = async () => {
|
||||
lastLoadedChannel.value = undefined;
|
||||
|
||||
const response = await client.value.request("channel/list");
|
||||
|
||||
if (!response.success) {
|
||||
return false;
|
||||
}
|
||||
|
||||
channels.value = response.channels;
|
||||
if (response.channels.length > 0) {
|
||||
lastLoadedChannel.value = response.channels[response.channels.length - 1]?.id;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export const loadChannels = async () => {
|
||||
const response = await client.value.request("channel/list", lastLoadedChannel.value ? {
|
||||
since: lastLoadedChannel.value,
|
||||
} : undefined);
|
||||
|
||||
if (!response.success) {
|
||||
return false;
|
||||
}
|
||||
|
||||
channels.value = channels.value.concat(response.channels);
|
||||
if (response.channels.length > 0) {
|
||||
lastLoadedChannel.value = response.channels[response.channels.length - 1]?.id;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,8 +1,19 @@
|
||||
import LynqChat from "lynqchat-js";
|
||||
import type ApiMap from "lynqchat-js/1.0.0-alpha.0/map";
|
||||
import Database, { getByIndex } from "./db";
|
||||
import { ref } from "vue";
|
||||
|
||||
const client = new LynqChat<ApiMap>({
|
||||
const client = ref<LynqChat<ApiMap>>(new LynqChat<ApiMap>({
|
||||
origin: window.origin,
|
||||
});
|
||||
}));
|
||||
|
||||
export const initClient = async () => {
|
||||
const db = new Database();
|
||||
const row = await getByIndex(db.settings, "name", "token");
|
||||
|
||||
if (row?.value) {
|
||||
client.value.token = row.value;
|
||||
}
|
||||
}
|
||||
|
||||
export default client;
|
||||
@@ -6,14 +6,7 @@ export interface Settings {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface Server {
|
||||
id: number;
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export default class extends Dexie {
|
||||
server!: EntityTable<Server, "id">;
|
||||
export default class Database extends Dexie {
|
||||
settings!: EntityTable<Settings, "id">;
|
||||
|
||||
constructor() {
|
||||
|
||||
Reference in New Issue
Block a user