2025-05-05 00:01:36 +08:00

63 lines
1.6 KiB
TypeScript

import { Connection } from './xhs-type/connection.ts';
import { Mention, CommonentInfo } from './xhs-type/mention.ts';
import { NoteFromHtml } from './xhs-type/note.ts';
const parseComment = (comment: CommonentInfo) => {
if (!comment) {
return null;
}
return {
comment_id: comment.id,
content: comment.content,
};
};
export class Parse {
static getComment(mention: Mention) {
const typeList = ['comment/item', 'mention/comment', 'comment/comment'];
if (typeList.includes(mention.type)) {
const comment_info = mention.comment_info;
const comment = parseComment(comment_info);
const target_comment = parseComment(comment_info.target_comment);
return {
...comment,
target_comment,
};
}
return null;
}
static getUser(mention: Mention) {
const user_info = mention?.item_info?.user_info;
if (user_info) {
return {
user_id: user_info.userid,
nickname: user_info.nickname,
image: user_info.image,
};
}
return null;
}
static getNote(note: NoteFromHtml) {
return {
node_id: note.note_id,
xsec_token: note.xsec_token,
time: note.time,
last_update_time: note.last_update_time,
desc: note.desc,
title: note.title,
image_list: note.image_list,
user: note.user,
};
}
static getConnects(message: Connection[]) {
return message.map((item) => {
const user = item.user;
return {
fstatus: user.fstatus,
xsec_token: user.xsec_token,
userid: user.userid,
nickname: user.nickname,
images: user.images,
};
});
}
}