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($("
    ").text(">").addClass("hashview-toolbar-child-marker")) ) @@ -577,9 +584,10 @@ export function aceCreateDomLine( if (!hashTitle) { throw new Error(`Unexpected error: ${searchHash_}, ${hash}, ${link}`); } + const basePath = getBasePath(); return [ { - extraOpenTags: ``, + extraOpenTags: ``, extraCloseTags: "", cls: modifiedCls, }, diff --git a/src/pad/static/js/result.ts b/src/pad/static/js/result.ts index f1e822f..28fae6b 100644 --- a/src/pad/static/js/result.ts +++ b/src/pad/static/js/result.ts @@ -1,4 +1,5 @@ import { SearchResponse } from "ep_search/setup"; +import { getBasePath } from "./util"; export function escapeForText(query: string): string { let escaped = query; @@ -34,8 +35,9 @@ export function query( if (rows !== undefined) { opts.push(`&rows=${rows}`); } + const basePath = getBasePath(); $.getJSON( - `/search/?query=${encodeURIComponent(query)}${opts.join("")}`, + `${basePath}/search/?query=${encodeURIComponent(query)}${opts.join("")}`, (data: SearchResponse) => { resolve(data); } diff --git a/src/pad/static/js/toolbar.ts b/src/pad/static/js/toolbar.ts index 8822664..b492427 100644 --- a/src/pad/static/js/toolbar.ts +++ b/src/pad/static/js/toolbar.ts @@ -1,3 +1,5 @@ +import { getBasePath } from "./util"; + export type Callbacks = { onSearch: (query: string) => void; onSort: (sort: string) => void; @@ -82,8 +84,9 @@ function createSearchBox( if (typeof query !== "string") { return; } + const basePath = getBasePath(); if (!onCreate) { - window.open(`/t/${encodeURIComponent(query)}`, "_blank"); + window.open(`${basePath}/t/${encodeURIComponent(query)}`, "_blank"); return; } onCreate(query); diff --git a/src/pad/static/js/util.ts b/src/pad/static/js/util.ts new file mode 100644 index 0000000..ce5404c --- /dev/null +++ b/src/pad/static/js/util.ts @@ -0,0 +1,19 @@ +export function getBasePath() { + // The path is in the form of .../p/id or .../t/title, so get the part before that + const path = window.location.pathname; + let index = path.indexOf("/p/"); + if (index < 0) { + index = path.indexOf("/t/"); + if (index < 0) { + console.warn("Base path not found", path); + // remove the last part of the path + const lastSlash = path.lastIndexOf("/"); + if (lastSlash >= 0) { + return path.substring(0, lastSlash); + } else { + return ""; + } + } + } + return path.substring(0, index); +} diff --git a/src/pad/templates/index.html b/src/pad/templates/index.html index bcd1def..e9ebacc 100644 --- a/src/pad/templates/index.html +++ b/src/pad/templates/index.html @@ -1,5 +1,5 @@ - - + +
    @@ -16,6 +16,9 @@ +