artalk 2.2.5 → 2.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Artalk.es.js CHANGED
@@ -2808,7 +2808,10 @@ function isValidURL(urlRaw) {
2808
2808
  return url.protocol === "http:" || url.protocol === "https:";
2809
2809
  }
2810
2810
  function getURLBasedOnApi(ctx, path) {
2811
- return `${ctx.conf.server.replace(/\/api\/?$/, "")}/${path.replace(/^\//, "")}`;
2811
+ return getURLBasedOn(ctx.conf.server, path);
2812
+ }
2813
+ function getURLBasedOn(baseURL, path) {
2814
+ return `${baseURL.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
2812
2815
  }
2813
2816
  function showLoading(parentElem, conf) {
2814
2817
  if (parentElem instanceof Context)
@@ -3191,7 +3194,7 @@ class Api {
3191
3194
  __publicField(this, "ctx");
3192
3195
  __publicField(this, "baseURL");
3193
3196
  this.ctx = ctx;
3194
- this.baseURL = ctx.conf.server;
3197
+ this.baseURL = `${ctx.conf.server}/api`;
3195
3198
  }
3196
3199
  get(offset, pageSize, flatMode, paramsEditor) {
3197
3200
  const params = {
@@ -3460,7 +3463,7 @@ const CaptchaChecker = {
3460
3463
  const $iframe = createElement(`<iframe class="atk-fade-in"></iframe>`);
3461
3464
  $iframe.style.display = "none";
3462
3465
  showLoading($iframeWrap, { transparentBg: true });
3463
- $iframe.src = `${that.ctx.conf.server}/captcha/get?t=${+new Date()}`;
3466
+ $iframe.src = `${that.ctx.conf.server}/api/captcha/get?t=${+new Date()}`;
3464
3467
  $iframe.onload = () => {
3465
3468
  $iframe.style.display = "";
3466
3469
  hideLoading($iframeWrap);
@@ -5434,7 +5437,7 @@ class ListLite extends Component {
5434
5437
  }
5435
5438
  this.data = data;
5436
5439
  const feMinVersion = ((_a = data.api_version) == null ? void 0 : _a.fe_min_version) || "0.0.0";
5437
- if (this.ctx.conf.versionCheck && this.versionCheck("\u524D\u7AEF", feMinVersion, "2.2.5"))
5440
+ if (this.ctx.conf.versionCheck && this.versionCheck("\u524D\u7AEF", feMinVersion, "2.2.6"))
5438
5441
  return;
5439
5442
  if (this.ctx.conf.versionCheck && this.versionCheck("\u540E\u7AEF", backendMinVersion, (_b = data.api_version) == null ? void 0 : _b.version))
5440
5443
  return;
@@ -5766,7 +5769,7 @@ class List extends ListLite {
5766
5769
  if (this.ctx.conf.listSort) {
5767
5770
  this.initDropdown();
5768
5771
  }
5769
- this.$el.querySelector(".atk-copyright").innerHTML = `Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${"2.2.5"}">Artalk</a>`;
5772
+ this.$el.querySelector(".atk-copyright").innerHTML = `Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${"2.2.6"}">Artalk</a>`;
5770
5773
  this.ctx.on("list-reload", () => this.fetchComments(0));
5771
5774
  this.ctx.on("list-refresh-ui", () => this.refreshUI());
5772
5775
  this.ctx.on("list-import", (data) => this.importComments(data));
@@ -5992,7 +5995,7 @@ class SidebarLayer extends Component {
5992
5995
  if (this.firstShow) {
5993
5996
  this.$iframeWrap.innerHTML = "";
5994
5997
  this.$iframe = createElement("<iframe></iframe>");
5995
- const baseURL = getURLBasedOnApi(this.ctx, "sidebar/");
5998
+ const baseURL = getURLBasedOnApi(this.ctx, "/sidebar/");
5996
5999
  const query = {
5997
6000
  pageKey: this.conf.pageKey,
5998
6001
  site: this.conf.site || "",
@@ -6065,18 +6068,25 @@ const _Artalk = class {
6065
6068
  __publicField(this, "list");
6066
6069
  __publicField(this, "sidebarLayer");
6067
6070
  this.conf = __spreadValues(__spreadValues({}, _Artalk.defaults), customConf);
6068
- this.conf.server = this.conf.server.replace(/\/$/, "");
6071
+ this.conf.server = this.conf.server.replace(/\/$/, "").replace(/\/api\/?$/, "");
6069
6072
  if (!this.conf.pageKey) {
6070
- this.conf.pageKey = `${window.location.protocol}//${window.location.host}${window.location.pathname}`;
6073
+ this.conf.pageKey = `${window.location.pathname}`;
6071
6074
  }
6072
- try {
6073
- const $root = document.querySelector(this.conf.el);
6074
- if (!$root)
6075
- throw Error(`Sorry, target element "${this.conf.el}" was not found.`);
6076
- this.$root = $root;
6077
- } catch (e) {
6078
- console.error(e);
6079
- throw new Error("Please check your Artalk `el` config.");
6075
+ if (!this.conf.pageTitle) {
6076
+ this.conf.pageTitle = `${document.title}`;
6077
+ }
6078
+ if (!!this.conf.el && this.conf.el instanceof HTMLElement) {
6079
+ this.$root = this.conf.el;
6080
+ } else {
6081
+ try {
6082
+ const $root = document.querySelector(this.conf.el);
6083
+ if (!$root)
6084
+ throw Error(`Sorry, target element "${this.conf.el}" was not found.`);
6085
+ this.$root = $root;
6086
+ } catch (e) {
6087
+ console.error(e);
6088
+ throw new Error("Please check your Artalk `el` config.");
6089
+ }
6080
6090
  }
6081
6091
  this.ctx = new Context(this.$root, this.conf);
6082
6092
  this.$root.classList.add("artalk");