mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-26 05:39:45 +08:00
✨ 帖子收藏 #100
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
/**
|
||||
* @file plugins Sqlite sql initData.ts
|
||||
* @file plugins/Sqlite/sql/initData.ts
|
||||
* @description Sqlite 初始化数据 sql 语句
|
||||
* @since Alpha v0.2.0
|
||||
* @since Beta v0.4.5
|
||||
*/
|
||||
|
||||
import { app } from "@tauri-apps/api";
|
||||
|
||||
import initTableSql from "./initTable";
|
||||
import {
|
||||
insertAchievementData,
|
||||
insertAchievementSeriesData,
|
||||
@@ -31,19 +32,21 @@ async function initAppData(): Promise<string[]> {
|
||||
const buildTime: string = getBuildTime();
|
||||
// 初始化应用版本
|
||||
sqlRes.push(`
|
||||
INSERT INTO AppData (key, value, updated)
|
||||
VALUES ('appVersion', '${appVersion}', datetime('now', 'localtime'))
|
||||
ON CONFLICT(key) DO UPDATE SET value = '${appVersion}', updated = datetime('now', 'localtime');`);
|
||||
INSERT INTO AppData (key, value, updated)
|
||||
VALUES ('appVersion', '${appVersion}', datetime('now', 'localtime'))
|
||||
ON CONFLICT(key) DO UPDATE SET value = '${appVersion}',
|
||||
updated = datetime('now', 'localtime');`);
|
||||
// 初始化应用数据更新时间
|
||||
sqlRes.push(`
|
||||
INSERT INTO AppData (key, value, updated)
|
||||
VALUES ('dataUpdated', '${buildTime}', datetime('now', 'localtime'))
|
||||
ON CONFLICT(key) DO UPDATE SET value = '${buildTime}', updated = datetime('now', 'localtime');`);
|
||||
INSERT INTO AppData (key, value, updated)
|
||||
VALUES ('dataUpdated', '${buildTime}', datetime('now', 'localtime'))
|
||||
ON CONFLICT(key) DO UPDATE SET value = '${buildTime}',
|
||||
updated = datetime('now', 'localtime');`);
|
||||
// 初始化 cookie
|
||||
sqlRes.push(`
|
||||
INSERT INTO AppData (key, value, updated)
|
||||
VALUES ('cookie', '{}', datetime('now', 'localtime'))
|
||||
ON CONFLICT(key) DO NOTHING;`);
|
||||
INSERT INTO AppData (key, value, updated)
|
||||
VALUES ('cookie', '{}', datetime('now', 'localtime'))
|
||||
ON CONFLICT(key) DO NOTHING;`);
|
||||
return sqlRes;
|
||||
}
|
||||
|
||||
@@ -85,11 +88,12 @@ function initCharacterData(): string[] {
|
||||
|
||||
/**
|
||||
* @description 初始化数据
|
||||
* @since Alpha v0.2.0
|
||||
* @since Beta v0.4.5
|
||||
* @returns {Promise<string[]>} sql
|
||||
*/
|
||||
async function initDataSql(): Promise<string[]> {
|
||||
const sqlRes: string[] = [];
|
||||
sqlRes.push(...initTableSql());
|
||||
sqlRes.push(...(await initAppData()));
|
||||
sqlRes.push(...initAchievementSeriesData());
|
||||
sqlRes.push(...initAchievementData());
|
||||
|
||||
@@ -269,3 +269,28 @@ export function insertRoleData(uid: string, data: TGApp.Game.Character.ListItem[
|
||||
});
|
||||
return sql.join("");
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 插入帖子收藏数据
|
||||
* @since Beta v0.4.5
|
||||
* @param {TGApp.Plugins.Mys.Post.FullData} data 帖子数据
|
||||
* @param {Array<string>} collect 合集
|
||||
* @param {string} uid 用户 UID
|
||||
* @returns {string} sql
|
||||
*/
|
||||
export function insertPostCollectData(
|
||||
data: TGApp.Plugins.Mys.Post.FullData,
|
||||
collect: string[],
|
||||
uid?: string,
|
||||
): string {
|
||||
return `
|
||||
INSERT INTO UserCollection (postId, title, content, collect, uid, updated)
|
||||
VALUES (${data.post.post_id}, '${data.post.subject}', '${JSON.stringify(data)}',
|
||||
'${JSON.stringify(collect)}', '${uid}', datetime('now', 'localtime'))
|
||||
ON CONFLICT DO UPDATE
|
||||
SET title = '${data.post.subject}',
|
||||
content = '${JSON.stringify(data)}',
|
||||
collect = '${JSON.stringify(collect)}',
|
||||
updated = datetime('now', 'localtime');
|
||||
`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user