From 3a01b0db69c24a82140a61720853f7dcbd0e0b3e Mon Sep 17 00:00:00 2001 From: neobooru <50623835+neobooru@users.noreply.github.com> Date: Tue, 19 May 2020 12:32:29 +0200 Subject: [PATCH] Fix issue where url would sometimes contain multiple slashes --- package.json | 2 +- src/Common.ts | 8 ++++++++ src/Config.ts | 3 +-- src/popup/App.vue | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index cf2101a..7c7060c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "szuru-chrome", - "version": "0.3.0", + "version": "0.3.1", "description": "Import media from various sites into szurubooru", "author": "neobooru", "license": "MIT", diff --git a/src/Common.ts b/src/Common.ts index 90efbd3..f4d58b4 100644 --- a/src/Common.ts +++ b/src/Common.ts @@ -22,3 +22,11 @@ export class Message { this.category = category ?? "none"; } } + +export function getUrl(root: string, ...parts: string[]): string { + let url = root.replace(/\/+$/, ""); + for (const part of parts) { + url += "/" + part.replace(/\/+$/, ""); + } + return url; +} diff --git a/src/Config.ts b/src/Config.ts index e88db12..766bfc4 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -15,7 +15,7 @@ export class Config { public async save() { await browser.storage.local.set({ - "config": JSON.stringify(this) + config: JSON.stringify(this) }); console.dir("Save " + JSON.stringify(this)); @@ -34,4 +34,3 @@ export class Config { return config; } } - diff --git a/src/popup/App.vue b/src/popup/App.vue index 473b12e..0d7ff76 100644 --- a/src/popup/App.vue +++ b/src/popup/App.vue @@ -110,7 +110,7 @@ import { ScrapedPost, ScrapedTag, ScrapeResults } from "neo-scraper"; import SzuruWrapper from "../SzuruWrapper"; import { Post, SzuruError } from "../SzuruTypes"; import { Config, SzuruSiteConfig } from "../Config"; -import { BrowserCommand, Message } from "../Common"; +import { BrowserCommand, Message, getUrl } from "../Common"; class ScrapedPostViewModel extends ScrapedPost { name: string = ""; @@ -247,7 +247,7 @@ export default Vue.extend({ }, getPostUrl(post: Post): string { if (!this.activeSite) return ""; - return this.activeSite.domain + "/post/" + post.id; + return getUrl(this.activeSite.domain, "post", post.id.toString()); }, // Add tag to the post's taglist addTag() {