mirror of
https://github.com/docmost/docmost.git
synced 2026-05-18 15:34:05 +08:00
cleanup
This commit is contained in:
@@ -14,14 +14,16 @@ import { StorageService } from '../storage/storage.service';
|
|||||||
import {
|
import {
|
||||||
buildTree,
|
buildTree,
|
||||||
computeLocalPath,
|
computeLocalPath,
|
||||||
ExportMetadata,
|
|
||||||
ExportPageMetadata,
|
|
||||||
getExportExtension,
|
getExportExtension,
|
||||||
getPageTitle,
|
getPageTitle,
|
||||||
PageExportTree,
|
PageExportTree,
|
||||||
replaceInternalLinks,
|
replaceInternalLinks,
|
||||||
updateAttachmentUrlsToLocalPaths,
|
updateAttachmentUrlsToLocalPaths,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
import {
|
||||||
|
ExportMetadata,
|
||||||
|
ExportPageMetadata,
|
||||||
|
} from '../../common/helpers/types/export-metadata.types';
|
||||||
import { PageRepo } from '@docmost/db/repos/page/page.repo';
|
import { PageRepo } from '@docmost/db/repos/page/page.repo';
|
||||||
import { Node } from '@tiptap/pm/model';
|
import { Node } from '@tiptap/pm/model';
|
||||||
import { EditorState } from '@tiptap/pm/state';
|
import { EditorState } from '@tiptap/pm/state';
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import * as path from 'path';
|
|||||||
import { Page } from '@docmost/db/types/entity.types';
|
import { Page } from '@docmost/db/types/entity.types';
|
||||||
import { isAttachmentNode } from '../../common/helpers/prosemirror/utils';
|
import { isAttachmentNode } from '../../common/helpers/prosemirror/utils';
|
||||||
|
|
||||||
export type { ExportMetadata, ExportPageMetadata } from '../../common/helpers/types/export-metadata.types';
|
|
||||||
|
|
||||||
export type PageExportTree = Record<string, Page[]>;
|
export type PageExportTree = Record<string, Page[]>;
|
||||||
|
|
||||||
export const INTERNAL_LINK_REGEX =
|
export const INTERNAL_LINK_REGEX =
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import { formatImportHtml } from '../utils/import-formatter';
|
|||||||
import {
|
import {
|
||||||
buildAttachmentCandidates,
|
buildAttachmentCandidates,
|
||||||
collectMarkdownAndHtmlFiles,
|
collectMarkdownAndHtmlFiles,
|
||||||
DocmostExportMetadata,
|
|
||||||
encodeFilePath,
|
encodeFilePath,
|
||||||
readDocmostMetadata,
|
readDocmostMetadata,
|
||||||
stripNotionID,
|
stripNotionID,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Logger } from '@nestjs/common';
|
import { Logger } from '@nestjs/common';
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import { ExportMetadata } from '../../../common/helpers/types/export-metadata.types';
|
||||||
|
|
||||||
export async function buildAttachmentCandidates(
|
export async function buildAttachmentCandidates(
|
||||||
extractDir: string,
|
extractDir: string,
|
||||||
@@ -35,9 +36,15 @@ export function resolveRelativeAttachmentPath(
|
|||||||
try {
|
try {
|
||||||
mainRel = decodeURIComponent(mainRel);
|
mainRel = decodeURIComponent(mainRel);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Logger.warn(`URI malformed for attachment path: ${mainRel}. Falling back to raw path.`, 'ImportUtils');
|
Logger.warn(
|
||||||
|
`URI malformed for attachment path: ${mainRel}. Falling back to raw path.`,
|
||||||
|
'ImportUtils',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const fallback = path.normalize(path.join(pageDir, mainRel)).split(path.sep).join('/');
|
const fallback = path
|
||||||
|
.normalize(path.join(pageDir, mainRel))
|
||||||
|
.split(path.sep)
|
||||||
|
.join('/');
|
||||||
|
|
||||||
if (attachmentCandidates.has(mainRel)) {
|
if (attachmentCandidates.has(mainRel)) {
|
||||||
return mainRel;
|
return mainRel;
|
||||||
@@ -78,16 +85,12 @@ export function stripNotionID(fileName: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function encodeFilePath(filePath: string): string {
|
export function encodeFilePath(filePath: string): string {
|
||||||
return filePath.split('/').map((segment) => encodeURIComponent(segment)).join('/');
|
return filePath
|
||||||
|
.split('/')
|
||||||
|
.map((segment) => encodeURIComponent(segment))
|
||||||
|
.join('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
export type {
|
|
||||||
ExportMetadata as DocmostExportMetadata,
|
|
||||||
ExportPageMetadata as DocmostExportPageMetadata,
|
|
||||||
} from '../../../common/helpers/types/export-metadata.types';
|
|
||||||
|
|
||||||
import type { ExportMetadata } from '../../../common/helpers/types/export-metadata.types';
|
|
||||||
|
|
||||||
export async function readDocmostMetadata(
|
export async function readDocmostMetadata(
|
||||||
extractDir: string,
|
extractDir: string,
|
||||||
): Promise<ExportMetadata | null> {
|
): Promise<ExportMetadata | null> {
|
||||||
@@ -95,7 +98,11 @@ export async function readDocmostMetadata(
|
|||||||
try {
|
try {
|
||||||
const content = await fs.readFile(metadataPath, 'utf-8');
|
const content = await fs.readFile(metadataPath, 'utf-8');
|
||||||
const metadata = JSON.parse(content) as ExportMetadata;
|
const metadata = JSON.parse(content) as ExportMetadata;
|
||||||
if (metadata.source === 'docmost' && metadata.version === 1 && metadata.pages) {
|
if (
|
||||||
|
metadata.source === 'docmost' &&
|
||||||
|
metadata.version === 1 &&
|
||||||
|
metadata.pages
|
||||||
|
) {
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user