Skip to content

Commit

Permalink
Do not upload images from same Danbooru instance
Browse files Browse the repository at this point in the history
  • Loading branch information
ZipFile committed Aug 9, 2024
1 parent b9e68db commit a4f0be7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/uploadURLGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export class UploadURLGeneratorImpl extends UploadURLGenerator {
generate(url, ref) {
const uploadUrl = new URL("uploads/new", this.prefix);

if (url.startsWith(this.prefix) || ref?.startsWith(this.prefix)) {
return uploadUrl;
}

if (!/^https?:\/\//.test(url)) {
return uploadUrl;
}
Expand Down
17 changes: 17 additions & 0 deletions test/test_uploadURLGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ describe("UploadURLGeneratorImpl", function() {
const srcUrl = "http://cdn.example.net/xxx.jpg";
const uploadURLGenerator = new UploadURLGeneratorImpl(prefix);

describe("generate() same prefix", function() {
it("src", function() {
const url = uploadURLGenerator.generate("http://example.com/data/360x360/aa/aa/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.jpg");

should(url.href).equal("http://example.com/uploads/new");
});

it("ref", function() {
const url = uploadURLGenerator.generate(
"http://cdn.example.com/data/360x360/aa/aa/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.jpg",
"http://example.com/posts/123456789",
);

should(url.href).equal("http://example.com/uploads/new");
});
});

it("generate() non http", function() {
const url = uploadURLGenerator.generate("chrome://newtab");

Expand Down

0 comments on commit a4f0be7

Please sign in to comment.