️ 已收藏帖子打开时自动更新数据

This commit is contained in:
目棃
2024-03-20 13:50:06 +08:00
parent 5d59245761
commit 88879dd4ec
4 changed files with 66 additions and 40 deletions

View File

@@ -221,6 +221,34 @@ async function deleteCollectPost(
return true;
}
/**
* @description 更新帖子信息
* @since Beta v0.4.5
* @param {DataBase} db 数据库
* @param {string} postId 文章 id
* @param {TGApp.Plugins.Mys.Post.FullData} post 文章信息
* @return {Promise<boolean>} 返回是否更新成功
*/
async function updatePostInfo(
db: DataBase,
postId: string,
post: TGApp.Plugins.Mys.Post.FullData,
): Promise<boolean> {
const sql = "SELECT id FROM UFPost WHERE id = ?";
const res: Array<{ id: number }> = await db.select(sql, [postId]);
if (res.length === 0) {
return false;
}
const updateSql = "UPDATE UFPost SET title = ?, content = ?, updated = ? WHERE id = ?";
await db.execute(updateSql, [
post.post.subject,
JSON.stringify(post),
new Date().getTime(),
postId,
]);
return true;
}
/**
* @description 删除某个帖子的收藏,可选是否强制删除
* @since Beta v0.4.5
@@ -261,7 +289,7 @@ async function deletePostCollect(
* @param {string[]} collections 收藏合集标题
* @return {Promise<boolean>} 返回是否修改成功
*/
async function updateCollectPost(
async function updatePostCollect(
db: DataBase,
postId: string,
collections: string[],
@@ -305,7 +333,7 @@ async function updateCollectPost(
* @param {string} oldCollection 旧的收藏合集标题
* @return {Promise<boolean>} 返回是否修改成功
*/
async function updateCollectPosts(
async function updatePostsCollect(
db: DataBase,
postIds: string[],
collection: string,
@@ -372,10 +400,11 @@ const TSUserCollection = {
deleteCollect,
updateCollect,
addCollect,
updatePostInfo,
deleteCollectPost,
deletePostCollect,
updateCollectPost,
updateCollectPosts,
updatePostCollect,
updatePostsCollect,
};
export default TSUserCollection;

View File

@@ -269,28 +269,3 @@ 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');
`;
}