mirror of
https://github.com/outline/outline.git
synced 2026-11-26 23:50:14 +03:00
chore: Move link actions to their own module and inline link checks
This commit is contained in:
23 files changed
+226
-223
No files matched your search
@@ -55,7 +55,6 @@ import { UrlHelper } from "@shared/utils/UrlHelper";
|
||||
import {
|
||||
findNavigationNode,
|
||||
insertNavigationNode,
|
||||
isLinkNode,
|
||||
moveNavigationNode,
|
||||
removeNavigationNode,
|
||||
updateNavigationNode,
|
||||
@@ -1258,7 +1257,7 @@ class Collection extends ParanoidModel<
|
||||
const allDocumentIds: string[] = [];
|
||||
|
||||
const loopChildren = (node: NavigationNode) => {
|
||||
if (isLinkNode(node)) {
|
||||
if (node.type === NavigationNodeType.Link) {
|
||||
return;
|
||||
}
|
||||
allDocumentIds.push(node.id);
|
||||
@@ -1281,7 +1280,7 @@ class Collection extends ParanoidModel<
|
||||
linkId: string
|
||||
): { node: NavigationNode; parentDocumentId?: string } | undefined => {
|
||||
const result = findNavigationNode(this.documentStructure ?? [], linkId);
|
||||
return result && isLinkNode(result.node)
|
||||
return result && result.node.type === NavigationNodeType.Link
|
||||
? { node: result.node, parentDocumentId: result.parentId }
|
||||
: undefined;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Team } from "@server/models";
|
||||
import type { NavigationNode } from "@shared/types";
|
||||
import { NavigationNodeType } from "@shared/types";
|
||||
import { isLinkNode } from "@shared/utils/collections";
|
||||
|
||||
export interface PresentedNavigationNode {
|
||||
id: string;
|
||||
@@ -30,7 +29,10 @@ export default function presentNavigationNode(
|
||||
url: /^https?:\/\//.test(node.url)
|
||||
? node.url
|
||||
: new URL(node.url, team.url).href,
|
||||
type: isLinkNode(node) ? NavigationNodeType.Link : undefined,
|
||||
type:
|
||||
node.type === NavigationNodeType.Link
|
||||
? NavigationNodeType.Link
|
||||
: undefined,
|
||||
children: (node.children ?? []).map((child) =>
|
||||
presentNavigationNode(team, child)
|
||||
),
|
||||
|
||||
@@ -3,8 +3,7 @@ import { escapeRegExp } from "es-toolkit/compat";
|
||||
import type { ZipFile } from "yazl";
|
||||
import { errToString } from "@shared/utils/error";
|
||||
import type { NavigationNode } from "@shared/types";
|
||||
import { FileOperationFormat } from "@shared/types";
|
||||
import { isLinkNode } from "@shared/utils/collections";
|
||||
import { FileOperationFormat, NavigationNodeType } from "@shared/types";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import type { Collection } from "@server/models";
|
||||
import Attachment from "@server/models/Attachment";
|
||||
@@ -440,7 +439,7 @@ export default abstract class ExportDocumentTreeTask extends ExportTask {
|
||||
format: FileOperationFormat
|
||||
) {
|
||||
for (const node of nodes) {
|
||||
if (isLinkNode(node)) {
|
||||
if (node.type === NavigationNodeType.Link) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { ZipFile } from "yazl";
|
||||
import { omit } from "es-toolkit/compat";
|
||||
import type { NavigationNode } from "@shared/types";
|
||||
import { isLinkNode } from "@shared/utils/collections";
|
||||
import { NavigationNodeType, type NavigationNode } from "@shared/types";
|
||||
import env from "@server/env";
|
||||
import type { Collection, FileOperation } from "@server/models";
|
||||
import { Attachment, Document } from "@server/models";
|
||||
@@ -99,7 +98,7 @@ export default class ExportJSONTask extends ExportTask {
|
||||
|
||||
const addDocumentTree = async (nodes: NavigationNode[]) => {
|
||||
for (const node of nodes) {
|
||||
if (isLinkNode(node)) {
|
||||
if (node.type === NavigationNodeType.Link) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import type { Filter } from "@shared/helpers/FilterHelper";
|
||||
import { Op, Sequelize } from "sequelize";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import type { DirectionFilter, SortFilter } from "@shared/types";
|
||||
import { type NavigationNode } from "@shared/types";
|
||||
import { NavigationNodeType, type NavigationNode } from "@shared/types";
|
||||
import {
|
||||
DocumentPermission,
|
||||
ExportContentType,
|
||||
@@ -19,7 +19,6 @@ import {
|
||||
StatusFilter,
|
||||
UserRole,
|
||||
} from "@shared/types";
|
||||
import { isLinkNode } from "@shared/utils/collections";
|
||||
import { subtractDate } from "@shared/utils/date";
|
||||
import slugify from "@server/utils/slugify";
|
||||
import { Day } from "@shared/utils/time";
|
||||
@@ -291,7 +290,7 @@ router.post(
|
||||
});
|
||||
authorize(user, "readDocument", collection);
|
||||
documentIds = (collection.documentStructure || [])
|
||||
.filter((node) => !isLinkNode(node))
|
||||
.filter((node) => node.type !== NavigationNodeType.Link)
|
||||
.slice(offset, offset + limit)
|
||||
.map((node) => node.id);
|
||||
where[Op.and].push({ id: documentIds });
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { escape } from "es-toolkit/compat";
|
||||
import type { NavigationNode } from "@shared/types";
|
||||
import { isLinkNode } from "@shared/utils/collections";
|
||||
import { NavigationNodeType, type NavigationNode } from "@shared/types";
|
||||
|
||||
/**
|
||||
* Converts a navigation tree to a sitemap XML string, by traversing the nodes.
|
||||
@@ -17,7 +16,7 @@ export function navigationNodeToSitemap(
|
||||
|
||||
function collectUrls(node: NavigationNode, urls: string[]) {
|
||||
// Links point to other pages, which are not part of the share.
|
||||
if (isLinkNode(node)) {
|
||||
if (node.type === NavigationNodeType.Link) {
|
||||
return;
|
||||
}
|
||||
urls.push(`${baseUrl}${node.url}`);
|
||||
|
||||
Reference in new issue
Block a user