diff --git a/Dockerfile b/Dockerfile index 2f3e43d..c5082e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,6 @@ +ARG ETHERPAD_IMAGE_NAME="etherpad/etherpad" +ARG ETHERPAD_IMAGE_TAG="2" + FROM mcr.microsoft.com/devcontainers/typescript-node:18 AS build-stage COPY . /app/ep_weave @@ -5,14 +8,14 @@ RUN cd /app/ep_weave \ && ls -la /app/ep_weave \ && npm i --include dev && npm run build -FROM etherpad/etherpad:2 +FROM ${ETHERPAD_IMAGE_NAME}:${ETHERPAD_IMAGE_TAG} USER root COPY --from=build-stage /app/ep_weave /tmp/ep_weave # ep_search -RUN git clone -b feature/search-engine-ep2 https://github.com/yacchin1205/ep_search.git /tmp/ep_search \ +RUN git clone -b feature/search-engine https://github.com/NII-cloud-operation/ep_search.git /tmp/ep_search \ && cd /tmp/ep_search \ && ls -la /tmp/ep_search \ && npm pack diff --git a/src/pad/index.ts b/src/pad/index.ts index d2067d1..0b40fa6 100644 --- a/src/pad/index.ts +++ b/src/pad/index.ts @@ -17,6 +17,10 @@ const api = require("ep_etherpad-lite/node/db/API"); let apikey: string | null = null; +type PluginSettings = { + basePath?: string; +}; + async function getPadIdsByTitle(searchEngine: SearchEngine, title: string) { const results = await searchEngine.search( `title:"${escapeForText(title)}"` @@ -81,6 +85,8 @@ exports.registerRoute = ( args: ExpressCreateServerArgs, cb: (next: any) => void ) => { + const epWeavePluginSettings = (settings.ep_weave || {}) as PluginSettings; + const basePath = epWeavePluginSettings.basePath || ""; const pluginSettings = settings.ep_search || {}; const searchEngine = createSearchEngine(pluginSettings); const apikeyFilename = absolutePaths.makeAbsolute( @@ -141,7 +147,7 @@ exports.registerRoute = ( if (ids === null) { createNewPadForTitle(title, req) .then((id) => { - res.redirect(`/p/${id}`); + res.redirect(`${basePath}/p/${id}`); }) .catch((err) => { console.error( @@ -155,7 +161,7 @@ exports.registerRoute = ( }); return; } - res.redirect(`/p/${ids[0]}`); + res.redirect(`${basePath}/p/${ids[0]}`); }) .catch((err) => { console.error( diff --git a/src/pad/static/js/hashitem.ts b/src/pad/static/js/hashitem.ts index 72c70a4..f6e8bc0 100644 --- a/src/pad/static/js/hashitem.ts +++ b/src/pad/static/js/hashitem.ts @@ -1,5 +1,6 @@ import { PadType } from "ep_search/setup"; import { getColorFromTitle, contrastRatio } from "./color"; +import { getBasePath } from "./util"; function mostReadableColor(backgroundColor: string, colorCandidates: string[]) { const contrastRatios = colorCandidates.map((color) => @@ -25,9 +26,9 @@ export async function createHashItemView(doc: PadType) { "#cccccc", "#ffffff", ]); - + const basePath = getBasePath(); const anchor = $("") - .attr("href", `/p/${value}`) + .attr("href", `${basePath}/p/${value}`) .css("color", color) .text(title); const hashLink = $("
") diff --git a/src/pad/static/js/hashview.ts b/src/pad/static/js/hashview.ts index 7baebd0..34807b4 100644 --- a/src/pad/static/js/hashview.ts +++ b/src/pad/static/js/hashview.ts @@ -12,6 +12,7 @@ import { query, escapeForText } from "./result"; import { createToolbar, createCloseButton } from "./toolbar"; import { initResizer, windowResized } from "./resizer"; import { getHashQuery } from "./hash"; +import { getBasePath } from "./util"; type PadRef = { id: string; @@ -47,7 +48,8 @@ function getPadURL() { const url = new URL(window.location.href); url.search = ""; url.hash = ""; - url.pathname = `/t/${encodeURIComponent(ep_weave.title)}`; + const basePath = getBasePath(); + url.pathname = `${basePath}/t/${encodeURIComponent(ep_weave.title)}`; return url.toString(); } @@ -83,10 +85,11 @@ function overrideEmbedCommand(toolbar: AceToolbar) { } function refreshNavbar(navbar: JQuery, title: string) { + const basePath = getBasePath(); navbar.empty(); navbar.append( $("") - .attr("href", "/") + .attr("href", `${basePath}/`) .text("Index") .addClass("hashview-path-segment hashview-path-index") ); @@ -99,7 +102,7 @@ function refreshNavbar(navbar: JQuery, title: string) { $("") .addClass("hashview-path-segment") .text(segment) - .attr("href", `/t/${encodeURIComponent(parentPath)}`) + .attr("href", `${basePath}/t/${encodeURIComponent(parentPath)}`) ); navbar.append($("").addClass("hashview-path-separator").text("/")); } @@ -129,6 +132,7 @@ function getCurrentSort() { } function createMenuItem() { + const basePath = getBasePath(); const changeTitleButton = $("") .addClass("hashview-change-title btn") .on("click", () => { @@ -136,7 +140,7 @@ function createMenuItem() { return; } $.ajax({ - url: `/ep_weave/hashes?${new URLSearchParams({ + url: `${basePath}/ep_weave/hashes?${new URLSearchParams({ oldtitle: changedTitle.oldtitle, newtitle: changedTitle.newtitle, })}`, @@ -175,8 +179,9 @@ function createMenuItem() { return; } duplicatedPads.forEach((pad) => { + const basePath = getBasePath(); console.debug(logPrefix, "Open pad", pad); - window.open(`/p/${pad.id}`, "_blank"); + window.open(`${basePath}/p/${pad.id}`, "_blank"); }); }); return $("") @@ -332,10 +337,11 @@ async function loadHashView( (await Promise.all(hashViews)).forEach((hashView) => { container.append(hashView); }); + const basePath = getBasePath(); const titledPadExists = docs.some((doc) => doc.title === hash.substring(1)); if (title !== hash.substring(1) && !titledPadExists) { const anchor = $("") - .attr("href", `/t/${hash.substring(1)}`) + .attr("href", `${basePath}/t/${hash.substring(1)}`) .text(hash.substring(1)); const createClass = "hash-create"; const hashLink = $("") @@ -505,7 +511,8 @@ exports.postToolbarInit = (hook: any, context: PostToolbarInit) => { title += "/"; } title += query; - window.open(`/t/${encodeURIComponent(title)}`, "_blank"); + const basePath = getBasePath(); + window.open(`${basePath}/t/${encodeURIComponent(title)}`, "_blank"); }, }).prepend($("