Workaround for new danbooru bot protection
parent
b4e63c8c5e
commit
1fa42c94a6
|
|
@ -33,7 +33,7 @@
|
||||||
"deepmerge": "^4.3.1",
|
"deepmerge": "^4.3.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"markdown-it": "^14.0.0",
|
"markdown-it": "^14.0.0",
|
||||||
"neo-scraper": "^0.7.3",
|
"neo-scraper": "^0.7.4",
|
||||||
"normalize.css": "^8.0.1",
|
"normalize.css": "^8.0.1",
|
||||||
"pinia": "^2.1.7",
|
"pinia": "^2.1.7",
|
||||||
"primeflex": "^3.3.1",
|
"primeflex": "^3.3.1",
|
||||||
|
|
|
||||||
|
|
@ -148,10 +148,41 @@ export default class SzurubooruApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
async uploadTempFile(contentUrl: string): Promise<TemporaryFileUploadResult> {
|
async uploadTempFile(contentUrl: string): Promise<TemporaryFileUploadResult> {
|
||||||
|
// HACK: For some sources we need to download the image to the client and then upload it to szurubooru.
|
||||||
|
// We can't just pass the contentUrl because that would trigger the bot/hotlink protection.
|
||||||
|
|
||||||
|
if (contentUrl.indexOf("donmai.us") != -1) {
|
||||||
|
console.log("Upload from content");
|
||||||
|
return this.uploadTempFileFromContent(contentUrl);
|
||||||
|
} else {
|
||||||
|
console.log("Upload from URL");
|
||||||
|
return this.uploadTempFileFromUrl(contentUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async uploadTempFileFromUrl(contentUrl: string): Promise<TemporaryFileUploadResult> {
|
||||||
const obj = { contentUrl };
|
const obj = { contentUrl };
|
||||||
return (await this.apiPost("uploads", obj)).data;
|
return (await this.apiPost("uploads", obj)).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async uploadTempFileFromContent(contentUrl: string): Promise<TemporaryFileUploadResult> {
|
||||||
|
const content = await (await fetch(contentUrl)).blob();
|
||||||
|
|
||||||
|
const fullUrl = this.apiUrl + "uploads";
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("content", content);
|
||||||
|
|
||||||
|
const config: AxiosRequestConfig = {
|
||||||
|
method: "POST",
|
||||||
|
url: fullUrl,
|
||||||
|
data: formData,
|
||||||
|
};
|
||||||
|
|
||||||
|
config.headers = { ...this.baseHeaders, "Content-Type": "multipart/form-data" };
|
||||||
|
return (await this.execute(config)).data;
|
||||||
|
}
|
||||||
|
|
||||||
static createFromConfig(siteConfig: SzuruSiteConfig): SzurubooruApi {
|
static createFromConfig(siteConfig: SzuruSiteConfig): SzurubooruApi {
|
||||||
return new SzurubooruApi(siteConfig.domain, siteConfig.username, siteConfig.authToken);
|
return new SzurubooruApi(siteConfig.domain, siteConfig.username, siteConfig.authToken);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,12 @@ async function uploadPost(data: PostUploadCommandData) {
|
||||||
pushInfo();
|
pushInfo();
|
||||||
|
|
||||||
const contentToken = data.post.instanceSpecificData[data.selectedSite.id]?.contentToken;
|
const contentToken = data.post.instanceSpecificData[data.selectedSite.id]?.contentToken;
|
||||||
|
|
||||||
|
if (!contentToken) {
|
||||||
|
// TODO: If donmai URL is the source then we need to do the uploadTempFileFromContent here!
|
||||||
|
console.log("contentToken is undefined. Is could be a problem for some sources!");
|
||||||
|
}
|
||||||
|
|
||||||
const createdPost = await szuru.createPost(data.post, contentToken);
|
const createdPost = await szuru.createPost(data.post, contentToken);
|
||||||
|
|
||||||
info.state = "uploaded";
|
info.state = "uploaded";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue