mirror of
https://github.com/docmost/docmost.git
synced 2026-05-08 23:33:09 +08:00
cleanup
This commit is contained in:
@@ -14,14 +14,16 @@ import { StorageService } from '../storage/storage.service';
|
||||
import {
|
||||
buildTree,
|
||||
computeLocalPath,
|
||||
ExportMetadata,
|
||||
ExportPageMetadata,
|
||||
getExportExtension,
|
||||
getPageTitle,
|
||||
PageExportTree,
|
||||
replaceInternalLinks,
|
||||
updateAttachmentUrlsToLocalPaths,
|
||||
} from './utils';
|
||||
import {
|
||||
ExportMetadata,
|
||||
ExportPageMetadata,
|
||||
} from '../../common/helpers/types/export-metadata.types';
|
||||
import { PageRepo } from '@docmost/db/repos/page/page.repo';
|
||||
import { Node } from '@tiptap/pm/model';
|
||||
import { EditorState } from '@tiptap/pm/state';
|
||||
|
||||
@@ -7,8 +7,6 @@ import * as path from 'path';
|
||||
import { Page } from '@docmost/db/types/entity.types';
|
||||
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 const INTERNAL_LINK_REGEX =
|
||||
|
||||
@@ -24,7 +24,6 @@ import { formatImportHtml } from '../utils/import-formatter';
|
||||
import {
|
||||
buildAttachmentCandidates,
|
||||
collectMarkdownAndHtmlFiles,
|
||||
DocmostExportMetadata,
|
||||
encodeFilePath,
|
||||
readDocmostMetadata,
|
||||
stripNotionID,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { promises as fs } from 'fs';
|
||||
import * as path from 'path';
|
||||
import { ExportMetadata } from '../../../common/helpers/types/export-metadata.types';
|
||||
|
||||
export async function buildAttachmentCandidates(
|
||||
extractDir: string,
|
||||
@@ -35,9 +36,15 @@ export function resolveRelativeAttachmentPath(
|
||||
try {
|
||||
mainRel = decodeURIComponent(mainRel);
|
||||
} 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)) {
|
||||
return mainRel;
|
||||
@@ -78,16 +85,12 @@ export function stripNotionID(fileName: 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(
|
||||
extractDir: string,
|
||||
): Promise<ExportMetadata | null> {
|
||||
@@ -95,7 +98,11 @@ export async function readDocmostMetadata(
|
||||
try {
|
||||
const content = await fs.readFile(metadataPath, 'utf-8');
|
||||
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 null;
|
||||
|
||||
Reference in New Issue
Block a user