Compare commits

...

7 Commits

Author SHA1 Message Date
5506fe5e73 POC 2024-12-11 22:13:42 +00:00
1302b1b602 v0.6.1 2024-12-11 14:55:06 +00:00
89a3f4cfc2 v0.6.1 2024-12-11 14:54:19 +00:00
e48b1c0dae fix: markdown math import (#529)
* fix: markdown math block import

* fix: block and inline math import

* cleanup
2024-12-09 15:08:25 +00:00
4a2a5a7a4d fix: postgres and redis url validation (#548) 2024-12-09 14:56:15 +00:00
532001fd82 chore: fix linting (#544)
* fix: eslint (server)

* fix: eslint (client)

* commit package lock file

* fix linting
2024-12-09 14:51:31 +00:00
e6bf4cdd6c fix: fix markdown import file button (#542) 2024-12-06 12:26:55 +00:00
33 changed files with 1222 additions and 255 deletions

View File

@ -1,22 +0,0 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
'plugin:@tanstack/eslint-plugin-query/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
}

View File

@ -0,0 +1,36 @@
import js from "@eslint/js";
import globals from "globals";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import tseslint from "typescript-eslint";
import pluginQuery from "@tanstack/eslint-plugin-query";
export default tseslint.config(
{ ignores: ["dist"] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ["**/*.{ts,tsx}"],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
"react-hooks": reactHooks,
"react-refresh": reactRefresh,
"@tanstack/query": pluginQuery,
},
rules: {
...reactHooks.configs.recommended.rules,
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-unused-vars": "off",
"react-hooks/exhaustive-deps": "off",
"@typescript-eslint/no-unused-expressions": "off",
"no-useless-escape": "off",
},
},
);

View File

@ -6,6 +6,7 @@
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Docmost</title>
<!--meta-tags-->
</head>
<body>
<div id="root"></div>

View File

@ -1,12 +1,13 @@
{
"name": "client",
"private": true,
"version": "0.6.0",
"version": "0.6.1",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
"lint": "eslint .",
"preview": "vite preview",
"format": "prettier --write \"src/**/*.tsx\" \"src/**/*.ts\""
},
"dependencies": {
"@casl/ability": "^6.7.2",
@ -49,25 +50,27 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^5.61.4",
"@eslint/js": "^9.16.0",
"@tanstack/eslint-plugin-query": "^5.62.1",
"@types/file-saver": "^2.0.7",
"@types/js-cookie": "^3.0.6",
"@types/katex": "^0.16.7",
"@types/node": "22.10.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@typescript-eslint/eslint-plugin": "^8.16.0",
"@typescript-eslint/parser": "^8.16.0",
"@vitejs/plugin-react": "^4.3.4",
"eslint": "^9.15.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-react-refresh": "^0.4.16",
"globals": "^15.13.0",
"optics-ts": "^2.4.1",
"postcss": "^8.4.49",
"postcss-preset-mantine": "^1.17.0",
"postcss-simple-vars": "^7.0.1",
"prettier": "^3.4.1",
"typescript": "^5.7.2",
"typescript-eslint": "^8.17.0",
"vite": "^6.0.0"
}
}

View File

@ -62,6 +62,13 @@ export default function App() {
<>
<Routes>
<Route index element={<Navigate to="/home" />} />
<Route path={"/share/:id"} element={
<ErrorBoundary
fallback={<>Failed to load home. An error occurred.</>}
>
<Home />
</ErrorBoundary>
}/>
<Route path={"/login"} element={<LoginPage />} />
<Route path={"/invites/:invitationId"} element={<InviteSignup />} />
<Route path={"/setup/register"} element={<SetupWorkspace />} />

View File

@ -25,7 +25,6 @@ export function useCommentsQuery(
params: ICommentParams,
): UseQueryResult<IPagination<IComment>, Error> {
return useQuery({
// eslint-disable-next-line @tanstack/query/exhaustive-deps
queryKey: RQ_KEY(params.pageId),
queryFn: () => getPageComments(params),
enabled: !!params.pageId,

View File

@ -40,7 +40,7 @@ export default function DrawioView(props: NodeViewProps) {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = () => {
let base64data = (reader.result || '') as string;
const base64data = (reader.result || '') as string;
setInitialXML(base64data);
};
}

View File

@ -456,7 +456,7 @@ export const getSuggestionItems = ({
const fuzzyMatch = (query: string, target: string) => {
let queryIndex = 0;
target = target.toLowerCase();
for (let char of target) {
for (const char of target) {
if (query[queryIndex] === char) queryIndex++;
if (queryIndex === query.length) return true;
}

View File

@ -119,7 +119,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
return (
<>
<SimpleGrid cols={2}>
<FileButton onChange={handleFileUpload} accept="text/markdown" multiple>
<FileButton onChange={handleFileUpload} accept=".md" multiple>
{(props) => (
<Button
justify="start"

View File

@ -24,7 +24,7 @@ export default function SpaceSettingsModal({
const {data: space, isLoading} = useSpaceQuery(spaceId);
const spaceRules = space?.membership?.permissions;
const spaceAbility = useMemo(() => useSpaceAbility(spaceRules), [spaceRules]);
const spaceAbility = useSpaceAbility(spaceRules);
return (
<>

View File

@ -47,7 +47,7 @@ export function SpaceSidebar() {
const { data: space, isLoading, isError } = useGetSpaceBySlugQuery(spaceSlug);
const spaceRules = space?.membership?.permissions;
const spaceAbility = useMemo(() => useSpaceAbility(spaceRules), [spaceRules]);
const spaceAbility = useSpaceAbility(spaceRules);
if (!space) {
return <></>;

View File

@ -141,7 +141,6 @@ export function useGetInvitationQuery(
invitationId: string,
): UseQueryResult<any, Error> {
return useQuery({
// eslint-disable-next-line @tanstack/query/exhaustive-deps
queryKey: ["invitations", invitationId],
queryFn: () => getInvitationById({ invitationId }),
enabled: !!invitationId,

View File

@ -23,7 +23,7 @@ export default function Page() {
const { data: space } = useGetSpaceBySlugQuery(page?.space?.slug);
const spaceRules = space?.membership?.permissions;
const spaceAbility = useMemo(() => useSpaceAbility(spaceRules), [spaceRules]);
const spaceAbility = useSpaceAbility(spaceRules);
if (isLoading) {
return <></>;

View File

@ -1,25 +0,0 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};

View File

@ -0,0 +1,34 @@
import js from '@eslint/js';
import globals from 'globals';
import tseslint from 'typescript-eslint';
import eslintConfigPrettier from 'eslint-config-prettier';
/** @type {import('eslint').Linter.Config[]} */
export default [
js.configs.recommended,
...tseslint.configs.recommended,
eslintConfigPrettier,
{
ignores: ['eslint.config.mjs'],
},
{
languageOptions: {
globals: { ...globals.node, ...globals.jest },
sourceType: 'module',
parser: tseslint.parser,
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'prefer-rest-params': 'off',
'no-useless-catch': 'off',
'no-useless-escape': 'off',
},
},
];

View File

@ -1,6 +1,6 @@
{
"name": "server",
"version": "0.6.0",
"version": "0.6.1",
"description": "",
"author": "",
"private": true,
@ -76,6 +76,7 @@
"ws": "^8.18.0"
},
"devDependencies": {
"@eslint/js": "^9.16.0",
"@nestjs/cli": "^10.4.8",
"@nestjs/schematics": "^10.2.3",
"@nestjs/testing": "^10.4.9",
@ -90,11 +91,9 @@
"@types/pg": "^8.11.10",
"@types/supertest": "^6.0.2",
"@types/ws": "^8.5.13",
"@typescript-eslint/eslint-plugin": "^8.16.0",
"@typescript-eslint/parser": "^8.16.0",
"eslint": "^9.15.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"globals": "^15.13.0",
"jest": "^29.7.0",
"kysely-codegen": "^0.17.0",
"prettier": "^3.4.1",
@ -105,7 +104,8 @@
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.7.2"
"typescript": "^5.7.2",
"typescript-eslint": "^8.17.0"
},
"jest": {
"moduleFileExtensions": [

View File

@ -1,5 +1,8 @@
import { Controller, Get } from '@nestjs/common';
import { Controller, Get, Param, Res } from '@nestjs/common';
import { AppService } from './app.service';
import { FastifyReply } from "fastify";
import { join } from 'path';
import * as fs from 'node:fs';
@Controller()
export class AppController {
@ -9,4 +12,27 @@ export class AppController {
getHello(): string {
return this.appService.getHello();
}
@Get('/share/:id')
getShare(@Res({ passthrough: false}) res: FastifyReply, @Param() params: any): string {
const clientDistPath = join(
__dirname,
'..',
'..',
'client/dist',
);
if (fs.existsSync(clientDistPath)) {
console.log('exists')
const indexFilePath = join(clientDistPath, 'index.html');
const stream = fs.createReadStream(indexFilePath);
console.log(params.id)
res.type('text/html').send(stream);
console.log('found');
return;
}
console.log('end')
return this.appService.getHello();
}
}

View File

@ -1,4 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { customAlphabet } = require('fix-esm').require('nanoid');
const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';

View File

@ -52,7 +52,7 @@ export class AttachmentService {
// passing attachmentId to allow for updating diagrams
// instead of creating new files for each save
if (opts?.attachmentId) {
let existingAttachment = await this.attachmentRepo.findById(
const existingAttachment = await this.attachmentRepo.findById(
opts.attachmentId,
);
if (!existingAttachment) {

View File

@ -24,7 +24,9 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
try {
accessToken = JSON.parse(req.cookies?.authTokens)?.accessToken;
} catch {}
} catch {
throw new BadRequestException('Failed to parse access token');
}
return accessToken || this.extractTokenFromHeader(req);
},

View File

@ -5,7 +5,8 @@ import { InjectKysely } from 'nestjs-kysely';
import { KyselyDB } from '@docmost/db/types/kysely.types';
import { sql } from 'kysely';
import { PageRepo } from '@docmost/db/repos/page/page.repo';
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const tsquery = require('pg-tsquery')();
@Injectable()

View File

@ -33,13 +33,13 @@ export async function executeWithPagination<O, DB, TB extends keyof DB>(
.select((eb) => eb.ref(deferredJoinPrimaryKey).as('primaryKey'))
.execute()
// @ts-expect-error TODO: Fix the type here later
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
.then((rows) => rows.map((row) => row.primaryKey));
qb = qb
.where((eb) =>
primaryKeys.length > 0
? // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
?
eb(deferredJoinPrimaryKey, 'in', primaryKeys as any)
: eb(sql`1`, '=', 0),
)

View File

@ -11,14 +11,22 @@ import { plainToInstance } from 'class-transformer';
export class EnvironmentVariables {
@IsNotEmpty()
@IsUrl(
{ protocols: ['postgres', 'postgresql'], require_tld: false },
{
protocols: ['postgres', 'postgresql'],
require_tld: false,
allow_underscores: true,
},
{ message: 'DATABASE_URL must be a valid postgres connection string' },
)
DATABASE_URL: string;
@IsNotEmpty()
@IsUrl(
{ protocols: ['redis', 'rediss'], require_tld: false },
{
protocols: ['redis', 'rediss'],
require_tld: false,
allow_underscores: true,
},
{ message: 'REDIS_URL must be a valid redis connection string' },
)
REDIS_URL: string;

View File

@ -42,7 +42,7 @@ export class ExportService {
content: [{ type: 'text', text: getPageTitle(page.title) }],
};
let prosemirrorJson: any = getProsemirrorContent(page.content);
const prosemirrorJson: any = getProsemirrorContent(page.content);
if (page.title) {
prosemirrorJson.content.unshift(titleNode);

View File

@ -117,7 +117,7 @@ function mathBlock(turndownService: TurndownService) {
);
},
replacement: function (content: any, node: HTMLInputElement) {
return `\n$$${content}$$\n`;
return `\n$$\n${content}\n$$\n`;
},
});
}

View File

@ -1,5 +1,7 @@
import { marked } from 'marked';
import { calloutExtension } from './callout.marked';
import { mathBlockExtension } from './math-block.marked';
import { mathInlineExtension } from "./math-inline.marked";
marked.use({
renderer: {
@ -26,7 +28,7 @@ marked.use({
},
});
marked.use({ extensions: [calloutExtension] });
marked.use({ extensions: [calloutExtension, mathBlockExtension, mathInlineExtension] });
export async function markdownToHtml(markdownInput: string): Promise<string> {
const YAML_FONT_MATTER_REGEX = /^\s*---[\s\S]*?---\s*/;

View File

@ -0,0 +1,37 @@
import { Token, marked } from 'marked';
interface MathBlockToken {
type: 'mathBlock';
text: string;
raw: string;
}
export const mathBlockExtension = {
name: 'mathBlock',
level: 'block',
start(src: string) {
return src.match(/\$\$/)?.index ?? -1;
},
tokenizer(src: string): MathBlockToken | undefined {
const rule = /^\$\$(?!(\$))([\s\S]+?)\$\$/;
const match = rule.exec(src);
if (match) {
return {
type: 'mathBlock',
raw: match[0],
text: match[2]?.trim(),
};
}
},
renderer(token: Token) {
const mathBlockToken = token as MathBlockToken;
// parse to prevent escaping slashes
const latex = marked
.parse(mathBlockToken.text)
.toString()
.replace(/<(\/)?p>/g, '');
return `<div data-type="${mathBlockToken.type}" data-katex="true">${latex}</div>`;
},
};

View File

@ -0,0 +1,55 @@
import { Token, marked } from 'marked';
interface MathInlineToken {
type: 'mathInline';
text: string;
raw: string;
}
const inlineMathRegex = /^\$(?!\s)(.+?)(?<!\s)\$(?!\d)/;
export const mathInlineExtension = {
name: 'mathInline',
level: 'inline',
start(src: string) {
let index: number;
let indexSrc = src;
while (indexSrc) {
index = indexSrc.indexOf('$');
if (index === -1) {
return;
}
const f = index === 0 || indexSrc.charAt(index - 1) === ' ';
if (f) {
const possibleKatex = indexSrc.substring(index);
if (possibleKatex.match(inlineMathRegex)) {
return index;
}
}
indexSrc = indexSrc.substring(index + 1).replace(/^\$+/, '');
}
},
tokenizer(src: string): MathInlineToken | undefined {
const match = inlineMathRegex.exec(src);
if (match) {
return {
type: 'mathInline',
raw: match[0],
text: match[1]?.trim(),
};
}
},
renderer(token: Token) {
const mathInlineToken = token as MathInlineToken;
// parse to prevent escaping slashes
const latex = marked
.parse(mathInlineToken.text)
.toString()
.replace(/<(\/)?p>/g, '');
return `<span data-type="${mathInlineToken.type}" data-katex="true">${latex}</span>`;
},
};

View File

@ -25,7 +25,7 @@ export const mailDriverConfigProvider = {
const driver = environmentService.getMailDriver().toLocaleLowerCase();
switch (driver) {
case MailOption.SMTP:
case MailOption.SMTP: {
let auth = undefined;
if (
environmentService.getSmtpUsername() &&
@ -44,9 +44,10 @@ export const mailDriverConfigProvider = {
connectionTimeout: 30 * 1000, // 30 seconds
auth,
secure: environmentService.getSmtpSecure(),
ignoreTLS: environmentService.getSmtpIgnoreTLS()
ignoreTLS: environmentService.getSmtpIgnoreTLS(),
} as SMTPTransport.Options,
};
}
case MailOption.Postmark:
return {

View File

@ -41,7 +41,7 @@ export const storageDriverConfigProvider = {
};
case StorageOption.S3:
const s3Config = {
{ const s3Config = {
driver,
config: {
region: environmentService.getAwsS3Region(),
@ -68,7 +68,7 @@ export const storageDriverConfigProvider = {
};
}
return s3Config;
return s3Config; }
default:
throw new Error(`Unknown storage driver: ${driver}`);

View File

@ -24,7 +24,7 @@ async function bootstrap() {
},
);
app.setGlobalPrefix('api');
app.setGlobalPrefix('api', { exclude: ['share/:id']});
const redisIoAdapter = new WsRedisIoAdapter(app);
await redisIoAdapter.connectToRedis();

View File

@ -1,7 +1,7 @@
{
"name": "docmost",
"homepage": "https://docmost.com",
"version": "0.6.0",
"version": "0.6.1",
"private": true,
"scripts": {
"build": "nx run-many -t build",

1141
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff