1
0
mirror of https://github.com/koloml/furbooru-tagging-assistant.git synced 2025-12-24 07:12:57 +00:00

Re-fetching the detail image page to catch new tags and aliases list

This commit is contained in:
2024-04-09 23:24:15 +04:00
parent f12e8f17b2
commit a4328eae24
2 changed files with 22 additions and 6 deletions

View File

@@ -8,8 +8,8 @@ export default class ScrapedAPI {
* @return {Promise<Map<string,string>|null>} Updated tags and aliases list for updating internal cached state.
*/
async updateImageTags(imageId, callback) {
const formData = await new PostParser(imageId)
.resolveTagEditorFormData();
const postParser = new PostParser(imageId);
const formData = await postParser.resolveTagEditorFormData();
const tagsList = new Set(
formData
@@ -29,13 +29,18 @@ export default class ScrapedAPI {
Array.from(updateTagsList).join(', ')
);
const tagsSubmittedResponse = await fetch(`/images/${imageId}/tags`, {
await fetch(`/images/${imageId}/tags`, {
method: 'POST',
body: formData,
});
return PostParser.resolveTagsAndAliasesFromPost(
await PostParser.resolveFragmentFromResponse(tagsSubmittedResponse)
);
// We need to remove stored version of the document to request an updated version.
postParser.clear();
// Additional request to re-fetch the new list of tags and aliases. I couldn't find the way to request this list
// using official API.
// TODO Maybe it will be better to resolve aliases on the extension side somehow, maybe by requesting and caching
// aliases in storage.
return await postParser.resolveTagsAndAliases();
}
}

View File

@@ -35,6 +35,17 @@ export default class PostParser extends PageParser {
);
}
/**
* Resolve the tags and aliases mapping from the post page.
*
* @return {Promise<Map<string, string>|null>}
*/
async resolveTagsAndAliases() {
return PostParser.resolveTagsAndAliasesFromPost(
await this.resolveFragment()
);
}
/**
* Resolve the list of tags and aliases from the post content.
*