修复可能的崩溃

修复ApiKey配置消失
This commit is contained in:
Nanako 2024-12-10 13:02:15 +08:00
parent 44bbf7582e
commit 15968a8ec6
4 changed files with 78 additions and 21 deletions

View File

@ -1,5 +1,5 @@
{
"url": "http://192.168.1.104:3010",
"url": "https://nanako.site:51304",
"username": "Nanako",
"password": "Nasiko@90",
"ignoredFiles": [

View File

@ -87,16 +87,16 @@ const defaultSauceNAOResponse = {
};
let myLogger;
let SauceNAOErrStr;
const sauceNAOApiKeyID = 'sauceNAO_api_key';
class PicSearcherApp extends App_1.App {
constructor(info, logger, accessors) {
super(info, logger, accessors);
this.rootUrl = '';
this.sauceNAOApiKey = '';
this.sauceNAOApiKey = 'ac635e5f5011234871260aac1d37ac8360ed979c';
myLogger = logger;
}
async initialize(configurationExtend, environmentRead) {
this.rootUrl = await environmentRead.getEnvironmentVariables().getValueByName('ROOT_URL');
this.sauceNAOApiKey = await environmentRead.getSettings().getValueById('SauceNAOApiKey');
myLogger.log('rootUrl:', this.rootUrl);
return super.initialize(configurationExtend, environmentRead);
}
@ -114,20 +114,20 @@ class PicSearcherApp extends App_1.App {
await sendSearchResults(modify, message.room, result, author);
}
async onSettingUpdated(setting, configurationModify, read, http) {
if (setting.id === 'SauceNAOApiKey') {
if (setting.id === sauceNAOApiKeyID) {
this.sauceNAOApiKey = setting.value;
}
return super.onSettingUpdated(setting, configurationModify, read, http);
}
async extendConfiguration(configuration, environmentRead) {
await configuration.settings.provideSetting({
id: 'SauceNAOApiKey',
id: sauceNAOApiKeyID,
type: settings_1.SettingType.STRING,
packageValue: '',
required: true,
public: false,
i18nLabel: 'searcher_api_key_label',
i18nDescription: 'searcher_api_key_description',
i18nLabel: 'sauceNAO_api_key',
i18nDescription: 'sauceNAO_api_key_desc',
});
}
async sendMessage(textMessage, room, author, modify) {
@ -227,10 +227,12 @@ async function sendSearchResults(modify, room, results, appUser) {
continue;
}
const color = getInterpolatedColor(similarityValue);
const titleText = data.title || '未知标题';
const attachmentObject = {
title: {
value: `${data.title} (${header.similarity}%)`,
value: `${titleText} (${header.similarity}%)`,
},
text: header.index_name,
thumbnailUrl: header.thumbnail,
collapsed: attachments.length !== 0,
color,
@ -249,7 +251,7 @@ async function sendSearchResults(modify, room, results, appUser) {
});
}
}
if (data.pixiv_id) {
if (data.member_id) {
attachmentObject.actions.push({
type: messages_1.MessageActionType.BUTTON,
text: '作者Pixiv',
@ -298,9 +300,34 @@ async function sendSearchResults(modify, room, results, appUser) {
url: `https://www.imdb.com/title/${data.imdb_id}`,
});
}
if (data.member_name !== undefined) {
attachmentObject.author = {
name: data.member_name,
};
}
if (data.author_name !== undefined) {
attachmentObject.author = {
name: data.author_name,
};
}
if (Array.isArray(data.creator)) {
attachmentObject.author = {
name: data.creator.join(', '),
};
}
if (data.eng_name !== undefined) {
attachmentObject.author = {
name: data.eng_name,
};
}
if (data.jp_name !== undefined) {
attachmentObject.author = {
name: data.jp_name,
};
}
attachments.push(attachmentObject);
}
const successStr = `搜索成功,短时间内剩余查询次数:${results.header.short_remaining}/${results.header.short_limit},长时间内剩余查询次数:${results.header.long_remaining}/${results.header.long_limit}`;
const successStr = `搜索成功,30秒内剩余查询次数:${results.header.short_remaining}/${results.header.short_limit}24小时内剩余查询次数:${results.header.long_remaining}/${results.header.long_limit}`;
const text = attachments.length > 0 ? successStr : SauceNAOErrStr.length > 0 ? SauceNAOErrStr : '没有找到相关结果';
const messageBuilder = modify.getCreator().startMessage()
.setRoom(room)

View File

@ -222,10 +222,11 @@ const defaultSauceNAOResponse: ISauceNAOResponse = {
let myLogger: ILogger;
let SauceNAOErrStr: string;
const sauceNAOApiKeyID = 'sauceNAO_api_key';
export class PicSearcherApp extends App implements IPostMessageSent {
private rootUrl: string = '';
private sauceNAOApiKey: string = '';
private sauceNAOApiKey: string = 'ac635e5f5011234871260aac1d37ac8360ed979c';
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
super(info, logger, accessors);
@ -234,7 +235,6 @@ export class PicSearcherApp extends App implements IPostMessageSent {
public async initialize(configurationExtend: IConfigurationExtend, environmentRead: IEnvironmentRead): Promise<void> {
this.rootUrl = await environmentRead.getEnvironmentVariables().getValueByName('ROOT_URL');
this.sauceNAOApiKey = await environmentRead.getSettings().getValueById('SauceNAOApiKey');
myLogger.log('rootUrl:', this.rootUrl);
return super.initialize(configurationExtend, environmentRead);
}
@ -256,7 +256,7 @@ export class PicSearcherApp extends App implements IPostMessageSent {
}
public async onSettingUpdated(setting: ISetting, configurationModify: IConfigurationModify, read: IRead, http: IHttp): Promise<void> {
if (setting.id === 'SauceNAOApiKey') {
if (setting.id === sauceNAOApiKeyID) {
this.sauceNAOApiKey = setting.value;
}
return super.onSettingUpdated(setting, configurationModify, read, http);
@ -264,13 +264,13 @@ export class PicSearcherApp extends App implements IPostMessageSent {
protected async extendConfiguration(configuration: IConfigurationExtend, environmentRead: IEnvironmentRead): Promise<void> {
await configuration.settings.provideSetting({
id: 'SauceNAOApiKey',
id: sauceNAOApiKeyID,
type: SettingType.STRING,
packageValue: '',
required: true,
public: false,
i18nLabel: 'searcher_api_key_label',
i18nDescription: 'searcher_api_key_description',
i18nLabel: 'sauceNAO_api_key',
i18nDescription: 'sauceNAO_api_key_desc',
});
}
@ -419,11 +419,13 @@ async function sendSearchResults(
// Dynamically generate color
const color = getInterpolatedColor(similarityValue);
const titleText = data.title || '未知标题';
const attachmentObject: IMessageAttachment = {
title: {
value: `${data.title} (${header.similarity}%)`, // Title content
value: `${titleText} (${header.similarity}%)`, // Title content
} as IMessageAttachmentTitle,
text: header.index_name,
thumbnailUrl: header.thumbnail, // Optional: Image URL
collapsed: attachments.length !== 0, // First one expanded, others collapsed
color, // Dynamically set color
@ -443,7 +445,9 @@ async function sendSearchResults(
} as IMessageAction);
}
}
if (data.pixiv_id) {
// Add more buttons for different sources
if (data.member_id) {
attachmentObject.actions.push({
type: MessageActionType.BUTTON,
text: '作者Pixiv',
@ -493,10 +497,36 @@ async function sendSearchResults(
} as IMessageAction);
}
if (data.member_name !== undefined) {
attachmentObject.author = {
name: data.member_name,
} as IMessageAttachmentAuthor;
}
if (data.author_name !== undefined) {
attachmentObject.author = {
name: data.author_name,
} as IMessageAttachmentAuthor;
}
if (Array.isArray(data.creator)) {
attachmentObject.author = {
name: data.creator.join(', '),
} as IMessageAttachmentAuthor;
}
if (data.eng_name !== undefined) {
attachmentObject.author = {
name: data.eng_name,
} as IMessageAttachmentAuthor;
}
if (data.jp_name !== undefined) {
attachmentObject.author = {
name: data.jp_name,
} as IMessageAttachmentAuthor;
}
attachments.push(attachmentObject);
}
const successStr = `搜索成功,短时间内剩余查询次数:${results.header.short_remaining}/${results.header.short_limit},长时间内剩余查询次数:${results.header.long_remaining}/${results.header.long_limit}`;
const successStr = `搜索成功,30秒内剩余查询次数:${results.header.short_remaining}/${results.header.short_limit}24小时内剩余查询次数:${results.header.long_remaining}/${results.header.long_limit}`;
const text = attachments.length > 0 ? successStr : SauceNAOErrStr.length > 0 ? SauceNAOErrStr : '没有找到相关结果';
const messageBuilder = modify.getCreator().startMessage()

View File

@ -1,6 +1,6 @@
{
"id": "bf4f0997-e7b7-40ff-b2b7-ba2ce5a15542",
"version": "0.0.2",
"id": "bf4f0997-e7b7-40ff-b2b7-ba2ce5a15543",
"version": "0.0.3",
"requiredApiVersion": "^1.44.0",
"iconFile": "favicon.png",
"author": {