David Taylor 0ed4b09527
DEV: Move discourse-common/(utils|lib) to discourse/lib (#30733)
`discourse-common` was created in the past to share logic between the
'wizard' app and the main 'discourse' app. Since then, the wizard has
been consolidated into the main app, so the separation of
`discourse-common` is no longer useful.

This commit moves `discourse-common/(lib|utils)/*` into
`discourse/lib/*`, adds shims for the imports, and updates existing
uses in core.
2025-01-13 13:02:49 +00:00

37 lines
1003 B
JavaScript

import { ajax } from "discourse/lib/ajax";
import discourseComputed from "discourse/lib/decorators";
import DiscourseURL from "discourse/lib/url";
import Category from "discourse/models/category";
import RestModel from "discourse/models/rest";
export default class Permalink extends RestModel {
static findAll(filter) {
return ajax("/admin/permalinks.json").then(function (permalinks) {
let allLinks = permalinks.map((p) => Permalink.create(p));
let filteredLinks = filter
? allLinks.filter(
(p) => p.url.includes(filter) || p.external_url?.includes(filter)
)
: allLinks;
return { allLinks, filteredLinks };
});
}
@discourseComputed("category_id")
category(category_id) {
return Category.findById(category_id);
}
@discourseComputed("external_url")
linkIsExternal(external_url) {
return !DiscourseURL.isInternal(external_url);
}
@discourseComputed("url")
key(url) {
return url.replace("/", "_");
}
}