generated from tailored/router-db-template
feat: 自己的笔记也需要at才能评论了,优化一下
This commit is contained in:
@@ -7,6 +7,8 @@ export { XhsClient };
|
||||
type XhsClientOptions = {
|
||||
key: string;
|
||||
cookie: string;
|
||||
userid?: string;
|
||||
username?: string;
|
||||
signConfig?: {
|
||||
signUrl: string;
|
||||
};
|
||||
@@ -88,4 +90,37 @@ export class XhsServices {
|
||||
const xhsClient = this.map.get(this.getKey(key));
|
||||
return xhsClient;
|
||||
}
|
||||
getXhsUserInfo(key?: string) {
|
||||
const xhsClient = this.map.get(this.getKey(key));
|
||||
return {
|
||||
userid: xhsClient?.options?.userid || '',
|
||||
username: xhsClient?.options?.username || '',
|
||||
};
|
||||
}
|
||||
isOwner(user: { username: string; userid: string }, key?: string) {
|
||||
const xhsUserInfo = this.getXhsUserInfo(key);
|
||||
if (!xhsUserInfo.userid || !xhsUserInfo.username) {
|
||||
return false;
|
||||
}
|
||||
return user.userid === xhsUserInfo.userid;
|
||||
}
|
||||
setCookie(cookie: string, key?: string) {
|
||||
const xhsClient = this.map.get(this.getKey(key));
|
||||
if (xhsClient) {
|
||||
xhsClient.options.cookie = cookie;
|
||||
xhsClient.client.setCookie(cookie);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 设置用户信息
|
||||
* @param user
|
||||
* @param key
|
||||
*/
|
||||
setUserInfo(user: { userid: string; username: string }, key?: string) {
|
||||
const xhsClient = this.map.get(this.getKey(key));
|
||||
if (xhsClient) {
|
||||
xhsClient.options.userid = user.userid;
|
||||
xhsClient.options.username = user.username;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user