mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-19 15:26:59 +08:00
Compare commits
11 Commits
v0.26.3-be
...
v2026.2.18
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35e1411407 | ||
|
|
8f833388eb | ||
|
|
850e646ab9 | ||
|
|
728e02cab7 | ||
|
|
792164edd1 | ||
|
|
e3177e6837 | ||
|
|
42f2d2b337 | ||
|
|
9d7f4acaf1 | ||
|
|
9a1f600fc9 | ||
|
|
0f906ad623 | ||
|
|
09aa65c52a |
@@ -222,7 +222,7 @@
|
||||
},
|
||||
"SMTP.sender": {
|
||||
"type": "string",
|
||||
"description": "Sender of all the emails (e.g. \"AFFiNE Self Hosted <noreply@example.com>\")\n@default \"AFFiNE Self Hosted <noreply@example.com>\"\n@environment `MAILER_SENDER`",
|
||||
"description": "Sender of all the emails (e.g. \"AFFiNE Self Hosted <noreply@example.com>\")\n@default \"AFFiNE Self Hosted <noreply@example.com>\"\n@environment `MAILER_SENDER`",
|
||||
"default": "AFFiNE Self Hosted <noreply@example.com>"
|
||||
},
|
||||
"SMTP.ignoreTLS": {
|
||||
@@ -262,7 +262,7 @@
|
||||
},
|
||||
"fallbackSMTP.sender": {
|
||||
"type": "string",
|
||||
"description": "Sender of all the emails (e.g. \"AFFiNE Self Hosted <noreply@example.com>\")\n@default \"\"",
|
||||
"description": "Sender of all the emails (e.g. \"AFFiNE Self Hosted <noreply@example.com>\")\n@default \"\"",
|
||||
"default": ""
|
||||
},
|
||||
"fallbackSMTP.ignoreTLS": {
|
||||
|
||||
78
.github/workflows/release-desktop.yml
vendored
78
.github/workflows/release-desktop.yml
vendored
@@ -201,13 +201,44 @@ jobs:
|
||||
nmHoistingLimits: workspaces
|
||||
env:
|
||||
npm_config_arch: ${{ matrix.spec.arch }}
|
||||
- name: Download and overwrite packaged artifacts
|
||||
- name: Download packaged artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: packaged-${{ matrix.spec.platform }}-${{ matrix.spec.arch }}
|
||||
path: packaged-unsigned
|
||||
- name: unzip packaged artifacts
|
||||
run: Expand-Archive -Path packaged-unsigned/archive.zip -DestinationPath packages/frontend/apps/electron/out
|
||||
- name: Download signed packaged file diff
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: signed-packaged-${{ matrix.spec.platform }}-${{ matrix.spec.arch }}
|
||||
path: .
|
||||
- name: unzip file
|
||||
run: Expand-Archive -Path signed.zip -DestinationPath packages/frontend/apps/electron/out
|
||||
path: signed-packaged-diff
|
||||
- name: Apply signed packaged file diff
|
||||
shell: pwsh
|
||||
run: |
|
||||
$DiffRoot = 'signed-packaged-diff/files'
|
||||
$TargetRoot = 'packages/frontend/apps/electron/out'
|
||||
if (!(Test-Path -LiteralPath $DiffRoot)) {
|
||||
throw "Signed diff directory not found: $DiffRoot"
|
||||
}
|
||||
|
||||
Copy-Item -Path (Join-Path $DiffRoot '*') -Destination $TargetRoot -Recurse -Force
|
||||
|
||||
$ManifestPath = 'signed-packaged-diff/manifest.json'
|
||||
if (Test-Path -LiteralPath $ManifestPath) {
|
||||
$ManifestEntries = @(Get-Content -LiteralPath $ManifestPath | ConvertFrom-Json)
|
||||
foreach ($Entry in $ManifestEntries) {
|
||||
$TargetPath = Join-Path $TargetRoot $Entry.path
|
||||
if (!(Test-Path -LiteralPath $TargetPath -PathType Leaf)) {
|
||||
throw "Applied signed file not found: $($Entry.path)"
|
||||
}
|
||||
|
||||
$TargetHash = (Get-FileHash -Algorithm SHA256 -LiteralPath $TargetPath).Hash
|
||||
if ($TargetHash -ne $Entry.sha256) {
|
||||
throw "Signed file hash mismatch: $($Entry.path)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- name: Make squirrel.windows installer
|
||||
run: yarn affine @affine/electron make-squirrel --platform=${{ matrix.spec.platform }} --arch=${{ matrix.spec.arch }}
|
||||
@@ -267,13 +298,44 @@ jobs:
|
||||
arch: arm64
|
||||
runs-on: ${{ matrix.spec.runner }}
|
||||
steps:
|
||||
- name: Download and overwrite installer artifacts
|
||||
- name: Download installer artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: installer-${{ matrix.spec.platform }}-${{ matrix.spec.arch }}
|
||||
path: installer-unsigned
|
||||
- name: unzip installer artifacts
|
||||
run: Expand-Archive -Path installer-unsigned/archive.zip -DestinationPath packages/frontend/apps/electron/out/${{ env.BUILD_TYPE }}/make
|
||||
- name: Download signed installer file diff
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: signed-installer-${{ matrix.spec.platform }}-${{ matrix.spec.arch }}
|
||||
path: .
|
||||
- name: unzip file
|
||||
run: Expand-Archive -Path signed.zip -DestinationPath packages/frontend/apps/electron/out/${{ env.BUILD_TYPE }}/make
|
||||
path: signed-installer-diff
|
||||
- name: Apply signed installer file diff
|
||||
shell: pwsh
|
||||
run: |
|
||||
$DiffRoot = 'signed-installer-diff/files'
|
||||
$TargetRoot = 'packages/frontend/apps/electron/out/${{ env.BUILD_TYPE }}/make'
|
||||
if (!(Test-Path -LiteralPath $DiffRoot)) {
|
||||
throw "Signed diff directory not found: $DiffRoot"
|
||||
}
|
||||
|
||||
Copy-Item -Path (Join-Path $DiffRoot '*') -Destination $TargetRoot -Recurse -Force
|
||||
|
||||
$ManifestPath = 'signed-installer-diff/manifest.json'
|
||||
if (Test-Path -LiteralPath $ManifestPath) {
|
||||
$ManifestEntries = @(Get-Content -LiteralPath $ManifestPath | ConvertFrom-Json)
|
||||
foreach ($Entry in $ManifestEntries) {
|
||||
$TargetPath = Join-Path $TargetRoot $Entry.path
|
||||
if (!(Test-Path -LiteralPath $TargetPath -PathType Leaf)) {
|
||||
throw "Applied signed file not found: $($Entry.path)"
|
||||
}
|
||||
|
||||
$TargetHash = (Get-FileHash -Algorithm SHA256 -LiteralPath $TargetPath).Hash
|
||||
if ($TargetHash -ne $Entry.sha256) {
|
||||
throw "Signed file hash mismatch: $($Entry.path)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- name: Save artifacts
|
||||
run: |
|
||||
|
||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -148,7 +148,7 @@ jobs:
|
||||
name: Wait for approval
|
||||
with:
|
||||
secret: ${{ secrets.GITHUB_TOKEN }}
|
||||
approvers: darkskygit,pengx17,L-Sun,EYHN
|
||||
approvers: darkskygit
|
||||
minimum-approvals: 1
|
||||
fail-on-denial: true
|
||||
issue-title: Please confirm to release docker image
|
||||
|
||||
40
.github/workflows/windows-signer.yml
vendored
40
.github/workflows/windows-signer.yml
vendored
@@ -30,13 +30,43 @@ jobs:
|
||||
run: |
|
||||
cd ${{ env.ARCHIVE_DIR }}/out
|
||||
signtool sign /tr http://timestamp.globalsign.com/tsa/r6advanced1 /td sha256 /fd sha256 /a ${{ inputs.files }}
|
||||
- name: zip file
|
||||
shell: cmd
|
||||
- name: collect signed file diff
|
||||
shell: powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -File {0}
|
||||
run: |
|
||||
cd ${{ env.ARCHIVE_DIR }}
|
||||
7za a signed.zip .\out\*
|
||||
$OutDir = Join-Path '${{ env.ARCHIVE_DIR }}' 'out'
|
||||
$DiffDir = Join-Path '${{ env.ARCHIVE_DIR }}' 'signed-diff'
|
||||
$FilesDir = Join-Path $DiffDir 'files'
|
||||
New-Item -ItemType Directory -Path $FilesDir -Force | Out-Null
|
||||
|
||||
$SignedFiles = [regex]::Matches('${{ inputs.files }}', '"([^"]+)"') | ForEach-Object { $_.Groups[1].Value }
|
||||
if ($SignedFiles.Count -eq 0) {
|
||||
throw 'No files to sign were provided.'
|
||||
}
|
||||
|
||||
$Manifest = @()
|
||||
foreach ($RelativePath in $SignedFiles) {
|
||||
$SourcePath = Join-Path $OutDir $RelativePath
|
||||
if (!(Test-Path -LiteralPath $SourcePath -PathType Leaf)) {
|
||||
throw "Signed file not found: $RelativePath"
|
||||
}
|
||||
|
||||
$TargetPath = Join-Path $FilesDir $RelativePath
|
||||
$TargetDir = Split-Path -Parent $TargetPath
|
||||
if ($TargetDir) {
|
||||
New-Item -ItemType Directory -Path $TargetDir -Force | Out-Null
|
||||
}
|
||||
|
||||
Copy-Item -LiteralPath $SourcePath -Destination $TargetPath -Force
|
||||
$Manifest += [PSCustomObject]@{
|
||||
path = $RelativePath
|
||||
sha256 = (Get-FileHash -Algorithm SHA256 -LiteralPath $TargetPath).Hash
|
||||
}
|
||||
}
|
||||
|
||||
$Manifest | ConvertTo-Json -Depth 4 | Out-File -FilePath (Join-Path $DiffDir 'manifest.json') -Encoding utf8
|
||||
Write-Host "Collected $($SignedFiles.Count) signed files."
|
||||
- name: upload
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: signed-${{ inputs.artifact-name }}
|
||||
path: ${{ env.ARCHIVE_DIR }}/signed.zip
|
||||
path: ${{ env.ARCHIVE_DIR }}/signed-diff
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
"correctness": "error",
|
||||
"perf": "error"
|
||||
},
|
||||
"env": {
|
||||
"builtin": true,
|
||||
"es2026": true
|
||||
},
|
||||
"ignorePatterns": [
|
||||
"**/node_modules",
|
||||
".yarn",
|
||||
@@ -44,6 +48,34 @@
|
||||
"**/test-blocks.json"
|
||||
],
|
||||
"rules": {
|
||||
"no-empty-static-block": "error",
|
||||
"no-misleading-character-class": "error",
|
||||
"no-new-native-nonconstructor": "error",
|
||||
"no-unused-private-class-members": "error",
|
||||
"no-useless-backreference": "error",
|
||||
"react/display-name": "error",
|
||||
"react/rules-of-hooks": "error",
|
||||
"react/exhaustive-deps": "warn",
|
||||
"@typescript-eslint/prefer-for-of": "error",
|
||||
"@typescript-eslint/no-unsafe-function-type": "error",
|
||||
"@typescript-eslint/no-wrapper-object-types": "error",
|
||||
"no-restricted-imports": [
|
||||
"error",
|
||||
{
|
||||
"patterns": [
|
||||
{
|
||||
"group": ["**/dist"],
|
||||
"message": "Don't import from dist",
|
||||
"allowTypeImports": false
|
||||
},
|
||||
{
|
||||
"group": ["**/src"],
|
||||
"message": "Don't import from src",
|
||||
"allowTypeImports": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"no-await-in-loop": "allow",
|
||||
"no-redeclare": "allow",
|
||||
"promise/no-callback-in-promise": "allow",
|
||||
@@ -70,6 +102,14 @@
|
||||
"no-func-assign": "error",
|
||||
"no-global-assign": "error",
|
||||
"no-unused-vars": "error",
|
||||
"no-unused-expressions": [
|
||||
"error",
|
||||
{
|
||||
"allowShortCircuit": true,
|
||||
"allowTernary": true,
|
||||
"allowTaggedTemplates": true
|
||||
}
|
||||
],
|
||||
"no-ex-assign": "error",
|
||||
"no-loss-of-precision": "error",
|
||||
"no-fallthrough": "error",
|
||||
@@ -126,6 +166,7 @@
|
||||
"react/no-render-return-value": "error",
|
||||
"react/jsx-no-target-blank": "error",
|
||||
"react/jsx-no-comment-textnodes": "error",
|
||||
"react/no-array-index-key": "off",
|
||||
"typescript/consistent-type-imports": "error",
|
||||
"typescript/no-non-null-assertion": "error",
|
||||
"typescript/triple-slash-reference": "error",
|
||||
@@ -241,6 +282,42 @@
|
||||
"typescript/consistent-type-imports": "off",
|
||||
"import/no-cycle": "off"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
"packages/**/*.{ts,tsx}",
|
||||
"tools/**/*.{ts,tsx}",
|
||||
"blocksuite/**/*.{ts,tsx}"
|
||||
],
|
||||
"rules": {
|
||||
"react/exhaustive-deps": [
|
||||
"warn",
|
||||
{
|
||||
"additionalHooks": "(useAsyncCallback|useCatchEventCallback|useDraggable|useDropTarget|useRefEffect)"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
"**/__tests__/**/*",
|
||||
"**/*.stories.tsx",
|
||||
"**/*.spec.ts",
|
||||
"**/tests/**/*",
|
||||
"scripts/**/*",
|
||||
"**/benchmark/**/*",
|
||||
"**/__debug__/**/*",
|
||||
"**/e2e/**/*"
|
||||
],
|
||||
"rules": {
|
||||
"no-restricted-imports": "off"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["**/*.{ts,js,mjs}"],
|
||||
"rules": {
|
||||
"react/rules-of-hooks": "off"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
2
.vscode/settings.template.json
vendored
2
.vscode/settings.template.json
vendored
@@ -17,7 +17,7 @@
|
||||
"explorer.fileNesting.enabled": true,
|
||||
"explorer.fileNesting.patterns": {
|
||||
"*.js": "${capture}.js.map, ${capture}.min.js, ${capture}.d.ts, ${capture}.d.ts.map",
|
||||
"package.json": ".browserslist*, .circleci*, .codecov, .commitlint*, .cz-config.js, .czrc, .dlint.json, .dprint.json, .editorconfig, .eslint*, eslint.*, .firebase*, .flowconfig, .github*, .gitlab*, .gitpod*, .huskyrc*, .jslint*, .lighthouserc.*, .lintstagedrc*, .markdownlint*, .mocha*, .node-version, .nodemon*, .npm*, .nvmrc, .pm2*, .pnp.*, .pnpm*, .prettier*, .releaserc*, .sentry*, .stackblitz*, .styleci*, .stylelint*, .tazerc*, .textlint*, .tool-versions, .travis*, .versionrc*, .vscode*, .watchman*, .xo-config*, .yamllint*, .yarnrc*, Procfile, api-extractor.json, apollo.config.*, appveyor*, ava.config.*, azure-pipelines*, bower.json, build.config.*, commitlint*, dangerfile*, dlint.json, dprint.json, firebase.json, grunt*, gulp*, histoire.config.*, jasmine.*, jenkins*, jest.config.*, jsconfig.*, karma*, lerna*, lighthouserc.*, lint-staged*, nest-cli.*, netlify*, nodemon*, nx.*, package-lock.json, package.nls*.json, phpcs.xml, playwright.config.*, pm2.*, pnpm*, prettier*, pullapprove*, puppeteer.config.*, pyrightconfig.json, release-tasks.sh, renovate*, rollup.config.*, stylelint*, tsconfig.*, tsdoc.*, tslint*, tsup.config.*, turbo*, typedoc*, unlighthouse*, vercel*, vetur.config.*, vitest.*, webpack*, workspace.json, xo.config.*, yarn*, babel.*, .babelrc, project.json, oxlint.json, nyc.config.*",
|
||||
"package.json": ".browserslist*, .circleci*, .codecov, .commitlint*, .cz-config.js, .czrc, .dlint.json, .dprint.json, .editorconfig, .eslint*, eslint.*, .firebase*, .flowconfig, .github*, .gitlab*, .gitpod*, .huskyrc*, .jslint*, .lighthouserc.*, .lintstagedrc*, .markdownlint*, .mocha*, .node-version, .nodemon*, .npm*, .nvmrc, .pm2*, .pnp.*, .pnpm*, .prettier*, .releaserc*, .sentry*, .stackblitz*, .styleci*, .stylelint*, .tazerc*, .textlint*, .tool-versions, .travis*, .versionrc*, .vscode*, .watchman*, .xo-config*, .yamllint*, .yarnrc*, Procfile, api-extractor.json, apollo.config.*, appveyor*, ava.config.*, azure-pipelines*, bower.json, build.config.*, commitlint*, dangerfile*, dlint.json, dprint.json, firebase.json, grunt*, gulp*, histoire.config.*, jasmine.*, jenkins*, jest.config.*, jsconfig.*, karma*, lerna*, lighthouserc.*, lint-staged*, nest-cli.*, netlify*, nodemon*, nx.*, package-lock.json, package.nls*.json, phpcs.xml, playwright.config.*, pm2.*, pnpm*, prettier*, pullapprove*, puppeteer.config.*, pyrightconfig.json, release-tasks.sh, renovate*, rollup.config.*, stylelint*, tsconfig.*, tsdoc.*, tslint*, tsup.config.*, turbo*, typedoc*, unlighthouse*, vercel*, vetur.config.*, vitest.*, webpack*, workspace.json, xo.config.*, yarn*, babel.*, .babelrc, project.json, .oxlintrc.json, oxlint.json, nyc.config.*",
|
||||
"Cargo.toml": "Cargo.lock, rust-toolchain*, rustfmt.toml, .taplo.toml",
|
||||
"README.md": "LICENSE*, CHANGELOG.md, CODE_OF_CONDUCT.md, CONTRIBUTING.md, SECURITY.md, README.*",
|
||||
".gitignore": ".gitattributes, .dockerignore, .eslintignore, .prettierignore, .stylelintignore, .tslintignore, .yarnignore"
|
||||
|
||||
@@ -67,7 +67,7 @@ export const autoScrollOnBoundary = (
|
||||
};
|
||||
|
||||
const cancelBoxListen = effect(() => {
|
||||
box.value;
|
||||
void box.value;
|
||||
startUpdate();
|
||||
});
|
||||
|
||||
|
||||
@@ -24,12 +24,12 @@ import {
|
||||
DataViewUIBase,
|
||||
DataViewUILogicBase,
|
||||
} from '../../../core/view/data-view-base.js';
|
||||
import { LEFT_TOOL_BAR_WIDTH } from '../consts.js';
|
||||
import {
|
||||
type TableSingleView,
|
||||
TableViewRowSelection,
|
||||
type TableViewSelectionWithType,
|
||||
} from '../../index.js';
|
||||
import { LEFT_TOOL_BAR_WIDTH } from '../consts.js';
|
||||
} from '../selection.js';
|
||||
import type { TableSingleView } from '../table-view-manager.js';
|
||||
import { TableClipboardController } from './controller/clipboard.js';
|
||||
import { TableDragController } from './controller/drag.js';
|
||||
import { TableHotkeysController } from './controller/hotkeys.js';
|
||||
|
||||
@@ -60,10 +60,9 @@ export class BaseExtensionProvider<
|
||||
* @param context - The context object containing scope and registration function
|
||||
* @param option - Optional configuration options for the provider
|
||||
*/
|
||||
setup(context: Context<Scope>, option?: Options) {
|
||||
setup(_context: Context<Scope>, option?: Options) {
|
||||
if (option) {
|
||||
this.schema.parse(option);
|
||||
}
|
||||
context;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -884,7 +884,7 @@ export class ConnectionOverlay extends Overlay {
|
||||
private _setupThemeListener(): void {
|
||||
const themeService = this.gfx.std.get(ThemeProvider);
|
||||
this._themeDisposer = effect(() => {
|
||||
themeService.theme$;
|
||||
void themeService.theme$.value;
|
||||
this._emphasisColor = this._getEmphasisColor();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/await-thenable */
|
||||
import type {
|
||||
Template,
|
||||
TemplateCategory,
|
||||
|
||||
@@ -9,7 +9,7 @@ import rehypeParse from 'rehype-parse';
|
||||
import { unified } from 'unified';
|
||||
|
||||
import type { AffineTextAttributes } from '../../types/index.js';
|
||||
import { HtmlDeltaConverter } from '../html/delta-converter.js';
|
||||
import type { HtmlDeltaConverter } from '../html/delta-converter.js';
|
||||
import {
|
||||
rehypeInlineToBlock,
|
||||
rehypeWrapInlineElements,
|
||||
|
||||
@@ -873,7 +873,7 @@ export class PdfAdapter extends BaseAdapter<PdfAdapterFile> {
|
||||
return {
|
||||
table: {
|
||||
headerRows: 0,
|
||||
widths: Array(sortedColumns.length).fill('*'),
|
||||
widths: Array.from({ length: sortedColumns.length }, () => '*'),
|
||||
body: tableBody,
|
||||
},
|
||||
margin: [0, 5, 0, 5],
|
||||
|
||||
@@ -115,12 +115,9 @@ export async function printToPdf(
|
||||
) as HTMLDivElement;
|
||||
|
||||
// force light theme in print iframe
|
||||
iframe.contentWindow.document.documentElement.setAttribute(
|
||||
'data-theme',
|
||||
'light'
|
||||
);
|
||||
iframe.contentWindow.document.body.setAttribute('data-theme', 'light');
|
||||
importedRoot.setAttribute('data-theme', 'light');
|
||||
iframe.contentWindow.document.documentElement.dataset.theme = 'light';
|
||||
iframe.contentWindow.document.body.dataset.theme = 'light';
|
||||
importedRoot.dataset.theme = 'light';
|
||||
|
||||
// draw saved canvas image to canvas
|
||||
const allImportedCanvas = importedRoot.getElementsByTagName('canvas');
|
||||
|
||||
@@ -126,7 +126,7 @@ export class EdgelessZoomToolbar extends WithDisposable(LitElement) {
|
||||
|
||||
this.disposables.add(
|
||||
effect(() => {
|
||||
this.gfx.tool.currentToolName$.value;
|
||||
void this.gfx.tool.currentToolName$.value;
|
||||
this.requestUpdate();
|
||||
})
|
||||
);
|
||||
|
||||
@@ -289,7 +289,7 @@ export class AffineKeyboardToolbar extends SignalWatcher(
|
||||
this.disposables.add(
|
||||
effect(() => {
|
||||
const std = this.rootComponent.std;
|
||||
std.selection.value;
|
||||
void std.selection.value;
|
||||
// wait cursor updated
|
||||
requestAnimationFrame(() => {
|
||||
this._scrollCurrentBlockIntoView();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ExtensionType, Schema, Workspace } from '@blocksuite/store';
|
||||
// @ts-ignore
|
||||
// @ts-expect-error -- mammoth.browser has no compatible type declaration for this subpath.
|
||||
import { convertToHtml } from 'mammoth/mammoth.browser';
|
||||
|
||||
import { HtmlTransformer } from './html';
|
||||
|
||||
@@ -10,12 +10,12 @@ import { Container } from '@blocksuite/global/di';
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import { sha } from '@blocksuite/global/utils';
|
||||
import type {
|
||||
DocMeta,
|
||||
ExtensionType,
|
||||
Schema,
|
||||
Store,
|
||||
Workspace,
|
||||
} from '@blocksuite/store';
|
||||
import type { DocMeta } from '@blocksuite/store';
|
||||
import { extMimeMap, Transformer } from '@blocksuite/store';
|
||||
|
||||
import type { AssetMap, ImportedFileEntry, PathBlobIdMap } from './type.js';
|
||||
|
||||
@@ -171,9 +171,11 @@ export class Unzip {
|
||||
const fileExt =
|
||||
fileName.lastIndexOf('.') === -1 ? '' : fileName.split('.').at(-1);
|
||||
const mime = extMimeMap.get(fileExt ?? '');
|
||||
const content = new File([this.unzipped![path]], fileName, {
|
||||
type: mime ?? '',
|
||||
}) as Blob;
|
||||
const content = new File(
|
||||
[new Uint8Array(this.unzipped![path]).buffer],
|
||||
fileName,
|
||||
mime ? { type: mime } : undefined
|
||||
) as Blob;
|
||||
|
||||
const fixedPath = this.fixFileNameEncoding(path);
|
||||
|
||||
|
||||
@@ -27,10 +27,10 @@ async function exportDocs(
|
||||
titleMiddleware(collection.meta.docMetas),
|
||||
],
|
||||
});
|
||||
const snapshots = await Promise.all(docs.map(job.docToSnapshot));
|
||||
|
||||
await Promise.all(
|
||||
snapshots
|
||||
docs
|
||||
.map(job.docToSnapshot)
|
||||
.filter((snapshot): snapshot is DocSnapshot => !!snapshot)
|
||||
.map(async snapshot => {
|
||||
// Use the title and id as the snapshot file name
|
||||
|
||||
@@ -190,7 +190,7 @@ export class Clipboard extends LifeCycleWatcher {
|
||||
);
|
||||
}
|
||||
return slice;
|
||||
} catch (error) {
|
||||
} catch {
|
||||
const getDataByType = this._getDataByType(data);
|
||||
const slice = await this._getSnapshotByPriority(
|
||||
type => getDataByType(type),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { LifeCycleWatcher } from '../extension/index.js';
|
||||
import { BlockServiceIdentifier } from '../identifier.js';
|
||||
import { LifeCycleWatcher } from './lifecycle-watcher.js';
|
||||
|
||||
export class ServiceManager extends LifeCycleWatcher {
|
||||
static override readonly key = 'serviceManager';
|
||||
|
||||
@@ -87,6 +87,7 @@ export function batchRemoveChildren(
|
||||
}
|
||||
|
||||
uniqueElements.forEach(element => {
|
||||
// oxlint-disable-next-line unicorn/prefer-dom-node-remove
|
||||
container.removeChild(element);
|
||||
});
|
||||
}
|
||||
@@ -114,7 +115,9 @@ function traverse(
|
||||
});
|
||||
}
|
||||
|
||||
postCallBack && postCallBack(element);
|
||||
if (postCallBack) {
|
||||
postCallBack(element);
|
||||
}
|
||||
};
|
||||
|
||||
innerTraverse(element);
|
||||
|
||||
@@ -170,10 +170,10 @@ export class EditorHost extends SignalWatcher(
|
||||
...Object.values(widgetTags),
|
||||
];
|
||||
await Promise.all(
|
||||
elementsTags.map(tag => {
|
||||
elementsTags.map(async tag => {
|
||||
const element = this.renderRoot.querySelector(tag._$litStatic$);
|
||||
if (element instanceof LitElement) {
|
||||
return element.updateComplete;
|
||||
return await element.updateComplete;
|
||||
}
|
||||
return null;
|
||||
})
|
||||
|
||||
@@ -382,6 +382,7 @@ describe('addBlock', () => {
|
||||
|
||||
const doc0 = collection.createDoc('doc:home');
|
||||
const doc1 = collection.createDoc('space:doc1');
|
||||
// eslint-disable-next-line @typescript-eslint/await-thenable
|
||||
await Promise.all([doc0.load(), doc1.load()]);
|
||||
assert.equal(collection.docs.size, 2);
|
||||
const store0 = doc0.getStore({
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { minimatch } from 'minimatch';
|
||||
|
||||
import { SCHEMA_NOT_FOUND_MESSAGE } from '../consts.js';
|
||||
import { BlockSchema, type BlockSchemaType } from '../model/index.js';
|
||||
import { BlockSchema, type BlockSchemaType } from '../model/block/zod.js';
|
||||
import { SchemaValidateError } from './error.js';
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import {
|
||||
BlockModel,
|
||||
type DraftModel,
|
||||
type Store,
|
||||
toDraftModel,
|
||||
} from '../model/index';
|
||||
import { BlockModel } from '../model/block/block-model.js';
|
||||
import { type DraftModel, toDraftModel } from '../model/block/draft.js';
|
||||
import type { Store } from '../model/store/store.js';
|
||||
|
||||
type SliceData = {
|
||||
content: DraftModel[];
|
||||
|
||||
@@ -3,14 +3,11 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import { nextTick } from '@blocksuite/global/utils';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
import {
|
||||
BlockModel,
|
||||
type BlockSchemaType,
|
||||
type DraftModel,
|
||||
type Store,
|
||||
toDraftModel,
|
||||
} from '../model/index.js';
|
||||
import type { Schema } from '../schema/index.js';
|
||||
import { BlockModel } from '../model/block/block-model.js';
|
||||
import { type DraftModel, toDraftModel } from '../model/block/draft.js';
|
||||
import type { BlockSchemaType } from '../model/block/zod.js';
|
||||
import type { Store } from '../model/store/store.js';
|
||||
import type { Schema } from '../schema/schema.js';
|
||||
import { AssetsManager } from './assets.js';
|
||||
import { BaseBlockTransformer } from './base.js';
|
||||
import type {
|
||||
|
||||
@@ -5,6 +5,7 @@ import eslint from '@eslint/js';
|
||||
import tsParser from '@typescript-eslint/parser';
|
||||
import eslintConfigPrettier from 'eslint-config-prettier';
|
||||
import importX from 'eslint-plugin-import-x';
|
||||
import oxlint from 'eslint-plugin-oxlint';
|
||||
import react from 'eslint-plugin-react';
|
||||
import reactHooks from 'eslint-plugin-react-hooks';
|
||||
import simpleImportSort from 'eslint-plugin-simple-import-sort';
|
||||
@@ -16,7 +17,10 @@ const __require = createRequire(import.meta.url);
|
||||
|
||||
const rxjs = __require('@smarttools/eslint-plugin-rxjs');
|
||||
|
||||
const ignoreList = readFileSync('.prettierignore', 'utf-8')
|
||||
const ignoreList = readFileSync(
|
||||
new URL('.prettierignore', import.meta.url),
|
||||
'utf-8'
|
||||
)
|
||||
.split('\n')
|
||||
.filter(line => line.trim() && !line.startsWith('#'));
|
||||
|
||||
@@ -60,105 +64,51 @@ export default tseslint.config(
|
||||
'simple-import-sort': simpleImportSort,
|
||||
rxjs,
|
||||
unicorn,
|
||||
oxlint,
|
||||
},
|
||||
rules: {
|
||||
...eslint.configs.recommended.rules,
|
||||
...react.configs.recommended.rules,
|
||||
...react.configs['jsx-runtime'].rules,
|
||||
...reactHooks.configs.recommended.rules,
|
||||
...oxlint.configs.recommended.rules,
|
||||
// covered by TypeScript
|
||||
'no-dupe-args': 'off',
|
||||
// the following rules are disabled because they are covered by oxlint
|
||||
'array-callback-return': 'off',
|
||||
'constructor-super': 'off',
|
||||
eqeqeq: 'off',
|
||||
'getter-return': 'off',
|
||||
'for-direction': 'off',
|
||||
'require-yield': 'off',
|
||||
'use-isnan': 'off',
|
||||
'valid-typeof': 'off',
|
||||
'no-self-compare': 'off',
|
||||
'no-empty': 'off',
|
||||
'no-constant-binary-expression': 'off',
|
||||
'no-constructor-return': 'off',
|
||||
'no-func-assign': 'off',
|
||||
'no-global-assign': 'off',
|
||||
'no-ex-assign': 'off',
|
||||
'no-fallthrough': 'off',
|
||||
'no-irregular-whitespace': 'off',
|
||||
'no-control-regex': 'off',
|
||||
'no-with': 'off',
|
||||
'no-debugger': 'off',
|
||||
'no-const-assign': 'off',
|
||||
'no-import-assign': 'off',
|
||||
'no-setter-return': 'off',
|
||||
'no-obj-calls': 'off',
|
||||
'no-unsafe-negation': 'off',
|
||||
'no-dupe-class-members': 'off',
|
||||
'no-dupe-keys': 'off',
|
||||
'no-this-before-super': 'off',
|
||||
'no-empty-character-class': 'off',
|
||||
'no-useless-catch': 'off',
|
||||
'no-async-promise-executor': 'off',
|
||||
'no-unreachable': 'off',
|
||||
'no-duplicate-case': 'off',
|
||||
'no-empty-pattern': 'off',
|
||||
'no-unused-labels': 'off',
|
||||
'no-sparse-arrays': 'off',
|
||||
'no-delete-var': 'off',
|
||||
'no-compare-neg-zero': 'off',
|
||||
'no-redeclare': 'off',
|
||||
'no-case-declarations': 'off',
|
||||
'no-class-assign': 'off',
|
||||
'no-var': 'off',
|
||||
'no-self-assign': 'off',
|
||||
'no-inner-declarations': 'off',
|
||||
'no-dupe-else-if': 'off',
|
||||
'no-invalid-regexp': 'off',
|
||||
'no-unsafe-finally': 'off',
|
||||
'no-prototype-builtins': 'off',
|
||||
'no-shadow-restricted-names': 'off',
|
||||
'no-nonoctal-decimal-escape': 'off',
|
||||
'no-constant-condition': 'off',
|
||||
'no-useless-escape': 'off',
|
||||
'no-unsafe-optional-chaining': 'off',
|
||||
'no-extra-boolean-cast': 'off',
|
||||
'no-regex-spaces': 'off',
|
||||
'no-unused-vars': 'off',
|
||||
'no-undef': 'off',
|
||||
'no-cond-assign': 'off',
|
||||
'react/jsx-no-useless-fragment': 'off',
|
||||
'react/no-unknown-property': 'off',
|
||||
'react/no-string-refs': 'off',
|
||||
'react/no-direct-mutation-state': 'off',
|
||||
'react/require-render-return': 'off',
|
||||
'react/jsx-no-undef': 'off',
|
||||
'react/jsx-no-duplicate-props': 'off',
|
||||
'react/jsx-key': 'off',
|
||||
'react/no-danger-with-children': 'off',
|
||||
'react/no-unescaped-entities': 'off',
|
||||
'react/no-is-mounted': 'off',
|
||||
'react/no-find-dom-node': 'off',
|
||||
'react/no-children-prop': 'off',
|
||||
'react/no-render-return-value': 'off',
|
||||
'react/jsx-no-target-blank': 'off',
|
||||
'react/jsx-no-comment-textnodes': 'off',
|
||||
'react/prop-types': 'off',
|
||||
'react-hooks/immutability': 'off',
|
||||
'react-hooks/refs': 'off',
|
||||
'react-hooks/set-state-in-effect': 'off',
|
||||
'react-hooks/static-components': 'off',
|
||||
'react-hooks/use-memo': 'off',
|
||||
'sonarjs/no-useless-catch': 'off',
|
||||
'@typescript-eslint/consistent-type-imports': 'off',
|
||||
'@typescript-eslint/no-unused-vars': 'off',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/no-loss-of-precision': 'off',
|
||||
'@typescript-eslint/ban-ts-comment': 'off',
|
||||
'@typescript-eslint/triple-slash-reference': 'off',
|
||||
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
|
||||
'@typescript-eslint/no-duplicate-enum-values': 'off',
|
||||
'@typescript-eslint/no-extra-non-null-assertion': 'off',
|
||||
'@typescript-eslint/no-misused-new': 'off',
|
||||
'@typescript-eslint/prefer-for-of': 'error',
|
||||
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
|
||||
'@typescript-eslint/no-this-alias': 'off',
|
||||
'@typescript-eslint/prefer-as-const': 'off',
|
||||
'@typescript-eslint/no-var-requires': 'off',
|
||||
'@typescript-eslint/no-namespace': 'off',
|
||||
'@typescript-eslint/no-unnecessary-type-constraint': 'off',
|
||||
@@ -167,30 +117,13 @@ export default tseslint.config(
|
||||
'@typescript-eslint/no-empty-function': 'off',
|
||||
|
||||
// rules that are not supported by oxlint
|
||||
'no-unreachable-loop': 'error',
|
||||
'@typescript-eslint/no-unsafe-function-type': 'error',
|
||||
'@typescript-eslint/no-wrapper-object-types': 'error',
|
||||
'@typescript-eslint/unified-signatures': 'error',
|
||||
'@typescript-eslint/return-await': [
|
||||
'error',
|
||||
'error-handling-correctness-only',
|
||||
],
|
||||
'@typescript-eslint/no-restricted-imports': [
|
||||
'error',
|
||||
{
|
||||
patterns: [
|
||||
{
|
||||
group: ['**/dist'],
|
||||
message: "Don't import from dist",
|
||||
allowTypeImports: false,
|
||||
},
|
||||
{
|
||||
group: ['**/src'],
|
||||
message: "Don't import from src",
|
||||
allowTypeImports: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
'sonarjs/no-all-duplicated-branches': 'error',
|
||||
'sonarjs/no-element-overwrite': 'error',
|
||||
'sonarjs/no-empty-collection': 'error',
|
||||
@@ -198,7 +131,6 @@ export default tseslint.config(
|
||||
'sonarjs/no-identical-conditions': 'error',
|
||||
'sonarjs/no-identical-expressions': 'error',
|
||||
'sonarjs/no-ignored-return': 'error',
|
||||
'sonarjs/no-one-iteration-loop': 'error',
|
||||
'sonarjs/no-use-of-empty-return-value': 'error',
|
||||
'sonarjs/non-existent-operator': 'error',
|
||||
'sonarjs/no-collapsible-if': 'error',
|
||||
@@ -234,13 +166,6 @@ export default tseslint.config(
|
||||
'error',
|
||||
{ includeInternal: true },
|
||||
],
|
||||
'react-hooks/exhaustive-deps': [
|
||||
'warn',
|
||||
{
|
||||
additionalHooks:
|
||||
'(useAsyncCallback|useCatchEventCallback|useDraggable|useDropTarget|useRefEffect)',
|
||||
},
|
||||
],
|
||||
'rxjs/finnish': [
|
||||
'error',
|
||||
{
|
||||
@@ -304,7 +229,6 @@ export default tseslint.config(
|
||||
{ ignoreVoid: true },
|
||||
],
|
||||
'@typescript-eslint/no-misused-promises': 0,
|
||||
'@typescript-eslint/no-restricted-imports': 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
32
package.json
32
package.json
@@ -26,9 +26,10 @@
|
||||
"lint:eslint:fix": "yarn lint:eslint --fix --fix-type problem,suggestion,layout",
|
||||
"lint:prettier": "prettier --ignore-unknown --cache --check .",
|
||||
"lint:prettier:fix": "prettier --ignore-unknown --cache --write .",
|
||||
"lint:ox": "oxlint -c oxlint.json --deny-warnings",
|
||||
"lint": "yarn lint:eslint && yarn lint:prettier",
|
||||
"lint:fix": "yarn lint:eslint:fix && yarn lint:prettier:fix",
|
||||
"lint:ox": "oxlint --deny-warnings",
|
||||
"lint:ox:fix": "yarn lint:ox --fix",
|
||||
"lint": "yarn lint:ox && yarn lint:eslint && yarn lint:prettier",
|
||||
"lint:fix": "yarn lint:ox:fix && yarn lint:eslint:fix && yarn lint:prettier:fix",
|
||||
"test": "vitest --run",
|
||||
"test:ui": "vitest --ui",
|
||||
"test:coverage": "vitest run --coverage",
|
||||
@@ -51,7 +52,7 @@
|
||||
"devDependencies": {
|
||||
"@affine-tools/cli": "workspace:*",
|
||||
"@capacitor/cli": "^7.0.0",
|
||||
"@eslint/js": "^9.16.0",
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@faker-js/faker": "^10.1.0",
|
||||
"@istanbuljs/schema": "^0.1.3",
|
||||
"@magic-works/i18n-codegen": "^0.6.1",
|
||||
@@ -61,32 +62,33 @@
|
||||
"@toeverything/infra": "workspace:*",
|
||||
"@types/eslint": "^9.6.1",
|
||||
"@types/node": "^22.0.0",
|
||||
"@typescript-eslint/parser": "^8.18.0",
|
||||
"@typescript-eslint/parser": "^8.55.0",
|
||||
"@vanilla-extract/vite-plugin": "^5.0.0",
|
||||
"@vitest/browser": "^3.2.4",
|
||||
"@vitest/coverage-istanbul": "^3.2.4",
|
||||
"@vitest/ui": "^3.2.4",
|
||||
"cross-env": "^10.1.0",
|
||||
"electron": "^39.0.0",
|
||||
"eslint": "^9.16.0",
|
||||
"eslint-config-prettier": "^10.0.0",
|
||||
"eslint-import-resolver-typescript": "^4.0.0",
|
||||
"eslint-plugin-import-x": "^4.5.0",
|
||||
"eslint-plugin-react": "^7.37.2",
|
||||
"eslint-plugin-react-hooks": "^5.1.0",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-import-resolver-typescript": "^4.4.4",
|
||||
"eslint-plugin-import-x": "^4.16.1",
|
||||
"eslint-plugin-oxlint": "^1.46.0",
|
||||
"eslint-plugin-react": "^7.37.5",
|
||||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"eslint-plugin-simple-import-sort": "^12.1.1",
|
||||
"eslint-plugin-sonarjs": "^3.0.1",
|
||||
"eslint-plugin-unicorn": "^59.0.0",
|
||||
"eslint-plugin-sonarjs": "^3.0.7",
|
||||
"eslint-plugin-unicorn": "^63.0.0",
|
||||
"happy-dom": "^20.0.0",
|
||||
"husky": "^9.1.7",
|
||||
"lint-staged": "^16.0.0",
|
||||
"msw": "^2.12.4",
|
||||
"oxlint": "~1.18.0",
|
||||
"oxlint": "^1.47.0",
|
||||
"prettier": "^3.7.4",
|
||||
"semver": "^7.7.3",
|
||||
"serve": "^14.2.4",
|
||||
"typescript": "^5.7.2",
|
||||
"typescript-eslint": "^8.18.0",
|
||||
"typescript-eslint": "^8.55.0",
|
||||
"unplugin-swc": "^1.5.9",
|
||||
"vite": "^7.2.7",
|
||||
"vitest": "^3.2.4"
|
||||
|
||||
@@ -31,7 +31,7 @@ assert.strictEqual(
|
||||
bench
|
||||
.add('tiktoken', () => {
|
||||
const encoder = encoding_for_model('gpt-4o');
|
||||
encoder.encode_ordinary(FIXTURE).length;
|
||||
void encoder.encode_ordinary(FIXTURE).length;
|
||||
})
|
||||
.add('native', () => {
|
||||
fromModelName('gpt-4o').count(FIXTURE);
|
||||
|
||||
@@ -43,7 +43,6 @@ class MockR2Provider extends R2StorageProvider {
|
||||
|
||||
destroy() {}
|
||||
|
||||
// @ts-ignore expect override
|
||||
override async proxyPutObject(
|
||||
key: string,
|
||||
body: any,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { LookupAddress } from 'node:dns';
|
||||
|
||||
import type { ExecutionContext, TestFn } from 'ava';
|
||||
import ava from 'ava';
|
||||
import { LookupAddress } from 'dns';
|
||||
import Sinon from 'sinon';
|
||||
import type { Response } from 'supertest';
|
||||
|
||||
@@ -14,7 +15,6 @@ import { createTestingApp, TestingApp } from './utils';
|
||||
type TestContext = {
|
||||
app: TestingApp;
|
||||
};
|
||||
|
||||
const test = ava as TestFn<TestContext>;
|
||||
|
||||
const LookupAddressStub = (async (_hostname, options) => {
|
||||
|
||||
@@ -51,10 +51,10 @@ function parseKey(privateKey: string) {
|
||||
let priv: KeyObject;
|
||||
try {
|
||||
priv = createPrivateKey({ key: keyBuf, format: 'pem', type: 'pkcs8' });
|
||||
} catch (e1) {
|
||||
} catch {
|
||||
try {
|
||||
priv = createPrivateKey({ key: keyBuf, format: 'pem', type: 'sec1' });
|
||||
} catch (e2) {
|
||||
} catch {
|
||||
// As a last resort rely on auto-detection
|
||||
priv = createPrivateKey(keyBuf);
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ export class R2StorageProvider extends S3StorageProvider {
|
||||
body: Readable | Buffer | Uint8Array | string,
|
||||
options: { contentType?: string; contentLength?: number } = {}
|
||||
) {
|
||||
return this.client.putObject(key, body as any, {
|
||||
return this.client.putObject(key, this.normalizeBody(body), {
|
||||
contentType: options.contentType,
|
||||
contentLength: options.contentLength,
|
||||
});
|
||||
@@ -192,13 +192,24 @@ export class R2StorageProvider extends S3StorageProvider {
|
||||
key,
|
||||
uploadId,
|
||||
partNumber,
|
||||
body as any,
|
||||
this.normalizeBody(body),
|
||||
{ contentLength: options.contentLength }
|
||||
);
|
||||
|
||||
return result.etag;
|
||||
}
|
||||
|
||||
private normalizeBody(body: Readable | Buffer | Uint8Array | string) {
|
||||
// s3mini does not accept Node.js Readable directly.
|
||||
// Convert it to Web ReadableStream for compatibility.
|
||||
if (body instanceof Readable) {
|
||||
return Readable.toWeb(body);
|
||||
} else if (typeof body === 'string') {
|
||||
return this.encoder.encode(body);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
override async get(
|
||||
key: string,
|
||||
signedUrl?: boolean
|
||||
|
||||
@@ -281,7 +281,7 @@ export class S3StorageProvider implements StorageProvider {
|
||||
|
||||
this.logger.verbose(`Read object \`${key}\``);
|
||||
return {
|
||||
body: Readable.fromWeb(obj.body as any),
|
||||
body: Readable.fromWeb(obj.body),
|
||||
metadata: {
|
||||
contentType: contentType ?? 'application/octet-stream',
|
||||
contentLength: contentLength ?? 0,
|
||||
|
||||
@@ -22,12 +22,14 @@ function firstNonEmpty(...values: Array<string | undefined>) {
|
||||
}
|
||||
|
||||
export function getRequestClientIp(req: Request) {
|
||||
return firstNonEmpty(
|
||||
req.get('CF-Connecting-IP'),
|
||||
firstForwardedForIp(req.get('X-Forwarded-For')),
|
||||
req.get('X-Real-IP'),
|
||||
req.ip
|
||||
)!;
|
||||
return (
|
||||
firstNonEmpty(
|
||||
req.get('CF-Connecting-IP'),
|
||||
firstForwardedForIp(req.get('X-Forwarded-For')),
|
||||
req.get('X-Real-IP'),
|
||||
req.ip
|
||||
) ?? ''
|
||||
);
|
||||
}
|
||||
|
||||
export function getRequestTrackerId(req: Request) {
|
||||
@@ -39,6 +41,7 @@ export function getRequestTrackerId(req: Request) {
|
||||
req.get('X-Real-IP'),
|
||||
req.get('CF-Ray'),
|
||||
req.ip
|
||||
)!
|
||||
) ??
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ export async function assertSsrFSafeUrl(
|
||||
let addresses: string[];
|
||||
try {
|
||||
addresses = await resolveHostAddresses(hostname);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
throw createSsrfBlockedError('unresolvable_hostname', {
|
||||
url: url.toString(),
|
||||
hostname,
|
||||
|
||||
@@ -109,3 +109,45 @@ test('should record page view when rendering shared page', async t => {
|
||||
docContent.restore();
|
||||
record.restore();
|
||||
});
|
||||
|
||||
test('should return markdown content and skip page view when accept is text/markdown', async t => {
|
||||
const docId = randomUUID();
|
||||
const { app, adapter, models, docReader } = t.context;
|
||||
|
||||
const doc = new YDoc();
|
||||
const text = doc.getText('content');
|
||||
const updates: Buffer[] = [];
|
||||
|
||||
doc.on('update', update => {
|
||||
updates.push(Buffer.from(update));
|
||||
});
|
||||
|
||||
text.insert(0, 'markdown');
|
||||
await adapter.pushDocUpdates(workspace.id, docId, updates, user.id);
|
||||
await models.doc.publish(workspace.id, docId);
|
||||
|
||||
const markdown = Sinon.stub(docReader, 'getDocMarkdown').resolves({
|
||||
title: 'markdown-doc',
|
||||
markdown: '# markdown-doc',
|
||||
});
|
||||
const docContent = Sinon.stub(docReader, 'getDocContent');
|
||||
const record = Sinon.stub(
|
||||
models.workspaceAnalytics,
|
||||
'recordDocView'
|
||||
).resolves();
|
||||
|
||||
const res = await app
|
||||
.GET(`/workspace/${workspace.id}/${docId}`)
|
||||
.set('accept', 'text/markdown')
|
||||
.expect(200);
|
||||
|
||||
t.true(markdown.calledOnceWithExactly(workspace.id, docId, false));
|
||||
t.is(res.text, '# markdown-doc');
|
||||
t.true((res.headers['content-type'] as string).startsWith('text/markdown'));
|
||||
t.true(docContent.notCalled);
|
||||
t.true(record.notCalled);
|
||||
|
||||
markdown.restore();
|
||||
docContent.restore();
|
||||
record.restore();
|
||||
});
|
||||
|
||||
@@ -44,6 +44,12 @@ const staticPaths = new Set([
|
||||
'trash',
|
||||
]);
|
||||
|
||||
const markdownType = new Set([
|
||||
'text/markdown',
|
||||
'application/markdown',
|
||||
'text/x-markdown',
|
||||
]);
|
||||
|
||||
@Controller('/workspace')
|
||||
export class DocRendererController {
|
||||
private readonly logger = new Logger(DocRendererController.name);
|
||||
@@ -68,6 +74,21 @@ export class DocRendererController {
|
||||
.digest('hex');
|
||||
}
|
||||
|
||||
private async allowDocPreview(workspaceId: string, docId: string) {
|
||||
const allowSharing = await this.models.workspace.allowSharing(workspaceId);
|
||||
if (!allowSharing) return false;
|
||||
|
||||
let allowUrlPreview = await this.models.doc.isPublic(workspaceId, docId);
|
||||
|
||||
if (!allowUrlPreview) {
|
||||
// if page is private, but workspace url preview is on
|
||||
allowUrlPreview =
|
||||
await this.models.workspace.allowUrlPreview(workspaceId);
|
||||
}
|
||||
|
||||
return allowUrlPreview;
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Get('/*path')
|
||||
async render(@Req() req: Request, @Res() res: Response) {
|
||||
@@ -81,28 +102,55 @@ export class DocRendererController {
|
||||
|
||||
let opts: RenderOptions | null = null;
|
||||
// /workspace/:workspaceId/{:docId | staticPaths}
|
||||
const [, , workspaceId, subPath, ...restPaths] = req.path.split('/');
|
||||
const [, , workspaceId, sub, ...rest] = req.path.split('/');
|
||||
const isWorkspace =
|
||||
workspaceId && sub && !staticPaths.has(sub) && rest.length === 0;
|
||||
const isDocPath = isWorkspace && workspaceId !== sub;
|
||||
|
||||
if (
|
||||
isDocPath &&
|
||||
req.accepts().some(t => markdownType.has(t.toLowerCase()))
|
||||
) {
|
||||
try {
|
||||
const allowPreview = await this.allowDocPreview(workspaceId, sub);
|
||||
if (!allowPreview) {
|
||||
res.status(404).end();
|
||||
return;
|
||||
}
|
||||
|
||||
const markdown = await this.doc.getDocMarkdown(workspaceId, sub, false);
|
||||
if (markdown) {
|
||||
res.setHeader('Content-Type', 'text/markdown; charset=utf-8');
|
||||
res.send(markdown.markdown);
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
this.logger.error('failed to render markdown page', e);
|
||||
}
|
||||
|
||||
res.status(404).end();
|
||||
return;
|
||||
}
|
||||
|
||||
// /:workspaceId/:docId
|
||||
if (workspaceId && !staticPaths.has(subPath) && restPaths.length === 0) {
|
||||
if (isWorkspace) {
|
||||
try {
|
||||
opts =
|
||||
workspaceId === subPath
|
||||
? await this.getWorkspaceContent(workspaceId)
|
||||
: await this.getPageContent(workspaceId, subPath);
|
||||
opts = isDocPath
|
||||
? await this.getPageContent(workspaceId, sub)
|
||||
: await this.getWorkspaceContent(workspaceId);
|
||||
metrics.doc.counter('render').add(1);
|
||||
|
||||
if (opts && workspaceId !== subPath) {
|
||||
if (opts && isDocPath) {
|
||||
void this.models.workspaceAnalytics
|
||||
.recordDocView({
|
||||
workspaceId,
|
||||
docId: subPath,
|
||||
visitorId: this.buildVisitorId(req, workspaceId, subPath),
|
||||
docId: sub,
|
||||
visitorId: this.buildVisitorId(req, workspaceId, sub),
|
||||
isGuest: true,
|
||||
})
|
||||
.catch(error => {
|
||||
this.logger.warn(
|
||||
`Failed to record shared page view: ${workspaceId}/${subPath}`,
|
||||
`Failed to record shared page view: ${workspaceId}/${sub}`,
|
||||
error as Error
|
||||
);
|
||||
});
|
||||
@@ -124,20 +172,7 @@ export class DocRendererController {
|
||||
workspaceId: string,
|
||||
docId: string
|
||||
): Promise<RenderOptions | null> {
|
||||
const allowSharing = await this.models.workspace.allowSharing(workspaceId);
|
||||
if (!allowSharing) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let allowUrlPreview = await this.models.doc.isPublic(workspaceId, docId);
|
||||
|
||||
if (!allowUrlPreview) {
|
||||
// if page is private, but workspace url preview is on
|
||||
allowUrlPreview =
|
||||
await this.models.workspace.allowUrlPreview(workspaceId);
|
||||
}
|
||||
|
||||
if (allowUrlPreview) {
|
||||
if (await this.allowDocPreview(workspaceId, docId)) {
|
||||
return this.doc.getDocContent(workspaceId, docId);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ defineModuleConfig('mailer', {
|
||||
env: 'MAILER_PASSWORD',
|
||||
},
|
||||
'SMTP.sender': {
|
||||
desc: 'Sender of all the emails (e.g. "AFFiNE Self Hosted \<noreply@example.com\>")',
|
||||
desc: 'Sender of all the emails (e.g. "AFFiNE Self Hosted <noreply@example.com>")',
|
||||
default: 'AFFiNE Self Hosted <noreply@example.com>',
|
||||
env: 'MAILER_SENDER',
|
||||
},
|
||||
@@ -92,7 +92,7 @@ defineModuleConfig('mailer', {
|
||||
default: '',
|
||||
},
|
||||
'fallbackSMTP.sender': {
|
||||
desc: 'Sender of all the emails (e.g. "AFFiNE Self Hosted \<noreply@example.com\>")',
|
||||
desc: 'Sender of all the emails (e.g. "AFFiNE Self Hosted <noreply@example.com>")',
|
||||
default: '',
|
||||
},
|
||||
'fallbackSMTP.ignoreTLS': {
|
||||
|
||||
@@ -2,9 +2,11 @@ import { Body, Controller, Options, Post, Req, Res } from '@nestjs/common';
|
||||
import type { Request, Response } from 'express';
|
||||
|
||||
import { BadRequest, Throttle, UseNamedGuard } from '../../base';
|
||||
import type { CurrentUser as CurrentUserType } from '../auth';
|
||||
import { Public } from '../auth';
|
||||
import { CurrentUser } from '../auth';
|
||||
import {
|
||||
CurrentUser,
|
||||
type CurrentUser as CurrentUserType,
|
||||
Public,
|
||||
} from '../auth';
|
||||
import { TelemetryService } from './service';
|
||||
import { TelemetryAck, type TelemetryBatch } from './types';
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import {
|
||||
Args,
|
||||
Field,
|
||||
Info,
|
||||
InputType,
|
||||
Int,
|
||||
Mutation,
|
||||
@@ -14,6 +15,12 @@ import {
|
||||
ResolveField,
|
||||
Resolver,
|
||||
} from '@nestjs/graphql';
|
||||
import {
|
||||
type FragmentDefinitionNode,
|
||||
type GraphQLResolveInfo,
|
||||
Kind,
|
||||
type SelectionNode,
|
||||
} from 'graphql';
|
||||
import { SafeIntResolver } from 'graphql-scalars';
|
||||
|
||||
import { PaginationInput, URLHelper } from '../../../base';
|
||||
@@ -53,6 +60,44 @@ registerEnumType(AdminSharedLinksOrder, {
|
||||
name: 'AdminSharedLinksOrder',
|
||||
});
|
||||
|
||||
function hasSelectedField(
|
||||
selections: readonly SelectionNode[],
|
||||
fieldName: string,
|
||||
fragments: Record<string, FragmentDefinitionNode>
|
||||
): boolean {
|
||||
for (const selection of selections) {
|
||||
if (selection.kind === Kind.FIELD) {
|
||||
if (selection.name.value === fieldName) {
|
||||
return true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (selection.kind === Kind.INLINE_FRAGMENT) {
|
||||
if (
|
||||
hasSelectedField(
|
||||
selection.selectionSet.selections,
|
||||
fieldName,
|
||||
fragments
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const fragment = fragments[selection.name.value];
|
||||
if (
|
||||
fragment &&
|
||||
hasSelectedField(fragment.selectionSet.selections, fieldName, fragments)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@InputType()
|
||||
class ListWorkspaceInput {
|
||||
@Field(() => Int, { defaultValue: 20 })
|
||||
@@ -471,22 +516,40 @@ export class AdminWorkspaceResolver {
|
||||
})
|
||||
async adminDashboard(
|
||||
@Args('input', { nullable: true, type: () => AdminDashboardInput })
|
||||
input?: AdminDashboardInput
|
||||
input?: AdminDashboardInput,
|
||||
@Info() info?: GraphQLResolveInfo
|
||||
) {
|
||||
this.assertCloudOnly();
|
||||
const includeTopSharedLinks = Boolean(
|
||||
info?.fieldNodes.some(
|
||||
node =>
|
||||
node.selectionSet &&
|
||||
hasSelectedField(
|
||||
node.selectionSet.selections,
|
||||
'topSharedLinks',
|
||||
info.fragments
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
const dashboard = await this.models.workspaceAnalytics.adminGetDashboard({
|
||||
timezone: input?.timezone,
|
||||
storageHistoryDays: input?.storageHistoryDays,
|
||||
syncHistoryHours: input?.syncHistoryHours,
|
||||
sharedLinkWindowDays: input?.sharedLinkWindowDays,
|
||||
includeTopSharedLinks,
|
||||
});
|
||||
|
||||
return {
|
||||
...dashboard,
|
||||
topSharedLinks: dashboard.topSharedLinks.map(link => ({
|
||||
...link,
|
||||
shareUrl: this.url.link(`/workspace/${link.workspaceId}/${link.docId}`),
|
||||
})),
|
||||
topSharedLinks: includeTopSharedLinks
|
||||
? dashboard.topSharedLinks.map(link => ({
|
||||
...link,
|
||||
shareUrl: this.url.link(
|
||||
`/workspace/${link.workspaceId}/${link.docId}`
|
||||
),
|
||||
}))
|
||||
: [],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url';
|
||||
import pkg from '../package.json' with { type: 'json' };
|
||||
|
||||
declare global {
|
||||
// oxlint-disable-next-line no-shadow-restricted-names
|
||||
namespace globalThis {
|
||||
// oxlint-disable-next-line no-var
|
||||
var env: Readonly<Env>;
|
||||
|
||||
@@ -110,10 +110,10 @@ export class CalendarAccountModel extends BaseModel {
|
||||
refreshIntervalMinutes: data.refreshIntervalMinutes,
|
||||
};
|
||||
|
||||
if (!!accessToken) {
|
||||
if (accessToken) {
|
||||
updateData.accessToken = accessToken;
|
||||
}
|
||||
if (!!refreshToken) {
|
||||
if (refreshToken) {
|
||||
updateData.refreshToken = refreshToken;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ export class CopilotSessionModel extends BaseModel {
|
||||
if (typeof value !== 'string') {
|
||||
return value;
|
||||
}
|
||||
return value.replace(/\u0000/g, '') as T;
|
||||
return value.replaceAll('\0', '') as T;
|
||||
}
|
||||
|
||||
private sanitizeJsonValue<T>(value: T): T {
|
||||
|
||||
@@ -51,6 +51,7 @@ export type AdminDashboardOptions = {
|
||||
storageHistoryDays?: number;
|
||||
syncHistoryHours?: number;
|
||||
sharedLinkWindowDays?: number;
|
||||
includeTopSharedLinks?: boolean;
|
||||
};
|
||||
|
||||
export type AdminAllSharedLinksOptions = {
|
||||
@@ -262,6 +263,7 @@ export class WorkspaceAnalyticsModel extends BaseModel {
|
||||
90,
|
||||
DEFAULT_SHARED_LINK_WINDOW_DAYS
|
||||
);
|
||||
const includeTopSharedLinks = options.includeTopSharedLinks ?? true;
|
||||
|
||||
const now = new Date();
|
||||
|
||||
@@ -274,6 +276,66 @@ export class WorkspaceAnalyticsModel extends BaseModel {
|
||||
const storageFrom = addUtcDays(currentDay, -(storageHistoryDays - 1));
|
||||
const sharedFrom = addUtcDays(currentDay, -(sharedLinkWindowDays - 1));
|
||||
|
||||
const topSharedLinksPromise = includeTopSharedLinks
|
||||
? this.db.$queryRaw<
|
||||
{
|
||||
workspaceId: string;
|
||||
docId: string;
|
||||
title: string | null;
|
||||
publishedAt: Date | null;
|
||||
docUpdatedAt: Date | null;
|
||||
workspaceOwnerId: string | null;
|
||||
lastUpdaterId: string | null;
|
||||
views: bigint | number;
|
||||
uniqueViews: bigint | number;
|
||||
guestViews: bigint | number;
|
||||
lastAccessedAt: Date | null;
|
||||
}[]
|
||||
>`
|
||||
WITH view_agg AS (
|
||||
SELECT
|
||||
workspace_id,
|
||||
doc_id,
|
||||
COALESCE(SUM(total_views), 0) AS views,
|
||||
COALESCE(SUM(unique_views), 0) AS unique_views,
|
||||
COALESCE(SUM(guest_views), 0) AS guest_views,
|
||||
MAX(last_accessed_at) AS last_accessed_at
|
||||
FROM workspace_doc_view_daily
|
||||
WHERE date BETWEEN ${sharedFrom}::date AND ${currentDay}::date
|
||||
GROUP BY workspace_id, doc_id
|
||||
)
|
||||
SELECT
|
||||
wp.workspace_id AS "workspaceId",
|
||||
wp.page_id AS "docId",
|
||||
wp.title AS title,
|
||||
wp.published_at AS "publishedAt",
|
||||
sn.updated_at AS "docUpdatedAt",
|
||||
owner.user_id AS "workspaceOwnerId",
|
||||
sn.updated_by AS "lastUpdaterId",
|
||||
COALESCE(v.views, 0) AS views,
|
||||
COALESCE(v.unique_views, 0) AS "uniqueViews",
|
||||
COALESCE(v.guest_views, 0) AS "guestViews",
|
||||
v.last_accessed_at AS "lastAccessedAt"
|
||||
FROM workspace_pages wp
|
||||
LEFT JOIN snapshots sn
|
||||
ON sn.workspace_id = wp.workspace_id AND sn.guid = wp.page_id
|
||||
LEFT JOIN view_agg v
|
||||
ON v.workspace_id = wp.workspace_id AND v.doc_id = wp.page_id
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT user_id
|
||||
FROM workspace_user_permissions
|
||||
WHERE workspace_id = wp.workspace_id
|
||||
AND type = ${WorkspaceRole.Owner}
|
||||
AND status = 'Accepted'::"WorkspaceMemberStatus"
|
||||
ORDER BY created_at ASC
|
||||
LIMIT 1
|
||||
) owner ON TRUE
|
||||
WHERE wp.public = TRUE
|
||||
ORDER BY views DESC, "uniqueViews" DESC, "workspaceId" ASC, "docId" ASC
|
||||
LIMIT 10
|
||||
`
|
||||
: Promise.resolve([]);
|
||||
|
||||
const [
|
||||
syncCurrent,
|
||||
syncTimeline,
|
||||
@@ -350,63 +412,7 @@ export class WorkspaceAnalyticsModel extends BaseModel {
|
||||
AND created_at >= ${sharedFrom}
|
||||
AND created_at <= ${now}
|
||||
`,
|
||||
this.db.$queryRaw<
|
||||
{
|
||||
workspaceId: string;
|
||||
docId: string;
|
||||
title: string | null;
|
||||
publishedAt: Date | null;
|
||||
docUpdatedAt: Date | null;
|
||||
workspaceOwnerId: string | null;
|
||||
lastUpdaterId: string | null;
|
||||
views: bigint | number;
|
||||
uniqueViews: bigint | number;
|
||||
guestViews: bigint | number;
|
||||
lastAccessedAt: Date | null;
|
||||
}[]
|
||||
>`
|
||||
WITH view_agg AS (
|
||||
SELECT
|
||||
workspace_id,
|
||||
doc_id,
|
||||
COALESCE(SUM(total_views), 0) AS views,
|
||||
COALESCE(SUM(unique_views), 0) AS unique_views,
|
||||
COALESCE(SUM(guest_views), 0) AS guest_views,
|
||||
MAX(last_accessed_at) AS last_accessed_at
|
||||
FROM workspace_doc_view_daily
|
||||
WHERE date BETWEEN ${sharedFrom}::date AND ${currentDay}::date
|
||||
GROUP BY workspace_id, doc_id
|
||||
)
|
||||
SELECT
|
||||
wp.workspace_id AS "workspaceId",
|
||||
wp.page_id AS "docId",
|
||||
wp.title AS title,
|
||||
wp.published_at AS "publishedAt",
|
||||
sn.updated_at AS "docUpdatedAt",
|
||||
owner.user_id AS "workspaceOwnerId",
|
||||
sn.updated_by AS "lastUpdaterId",
|
||||
COALESCE(v.views, 0) AS views,
|
||||
COALESCE(v.unique_views, 0) AS "uniqueViews",
|
||||
COALESCE(v.guest_views, 0) AS "guestViews",
|
||||
v.last_accessed_at AS "lastAccessedAt"
|
||||
FROM workspace_pages wp
|
||||
LEFT JOIN snapshots sn
|
||||
ON sn.workspace_id = wp.workspace_id AND sn.guid = wp.page_id
|
||||
LEFT JOIN view_agg v
|
||||
ON v.workspace_id = wp.workspace_id AND v.doc_id = wp.page_id
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT user_id
|
||||
FROM workspace_user_permissions
|
||||
WHERE workspace_id = wp.workspace_id
|
||||
AND type = ${WorkspaceRole.Owner}
|
||||
AND status = 'Accepted'::"WorkspaceMemberStatus"
|
||||
ORDER BY created_at ASC
|
||||
LIMIT 1
|
||||
) owner ON TRUE
|
||||
WHERE wp.public = TRUE
|
||||
ORDER BY views DESC, "uniqueViews" DESC, "workspaceId" ASC, "docId" ASC
|
||||
LIMIT 10
|
||||
`,
|
||||
topSharedLinksPromise,
|
||||
]);
|
||||
|
||||
const storageHistorySeries = storageHistory.map(row => ({
|
||||
|
||||
@@ -22,8 +22,8 @@ import {
|
||||
CalendarProviderListCalendarsParams,
|
||||
CalendarProviderListEventsParams,
|
||||
CalendarProviderListEventsResult,
|
||||
CalendarProviderName,
|
||||
} from './def';
|
||||
import { CalendarProviderName } from './factory';
|
||||
import { CalendarSyncTokenInvalid } from './google';
|
||||
|
||||
const XML_PARSER = new XMLParser({
|
||||
@@ -113,7 +113,7 @@ const isRedirectStatus = (status: number) =>
|
||||
|
||||
const splitHeaderTokens = (value: string) =>
|
||||
value
|
||||
.split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/)
|
||||
.split(/,(?=(?:[^"]*"[^"]*")*[^"]*$)/)
|
||||
.map(token => token.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
|
||||
@@ -2,12 +2,7 @@ import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import type { CalendarAccount } from '@prisma/client';
|
||||
|
||||
import { CalendarProviderRequestError, Config, OnEvent } from '../../../base';
|
||||
import { CalendarProviderFactory } from './factory';
|
||||
|
||||
export enum CalendarProviderName {
|
||||
Google = 'google',
|
||||
CalDAV = 'caldav',
|
||||
}
|
||||
import { CalendarProviderFactory, CalendarProviderName } from './factory';
|
||||
|
||||
export interface CalendarProviderTokens {
|
||||
accessToken: string;
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import type { CalendarProvider } from './def';
|
||||
import { CalendarProviderName } from './def';
|
||||
export enum CalendarProviderName {
|
||||
Google = 'google',
|
||||
CalDAV = 'caldav',
|
||||
}
|
||||
|
||||
export interface CalendarProviderRef {
|
||||
provider: CalendarProviderName;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class CalendarProviderFactory {
|
||||
export class CalendarProviderFactory<
|
||||
TProvider extends CalendarProviderRef = CalendarProviderRef,
|
||||
> {
|
||||
private readonly logger = new Logger(CalendarProviderFactory.name);
|
||||
readonly #providers = new Map<CalendarProviderName, CalendarProvider>();
|
||||
readonly #providers = new Map<CalendarProviderName, TProvider>();
|
||||
|
||||
get providers() {
|
||||
return Array.from(this.#providers.keys());
|
||||
@@ -16,12 +24,12 @@ export class CalendarProviderFactory {
|
||||
return this.#providers.get(name);
|
||||
}
|
||||
|
||||
register(provider: CalendarProvider) {
|
||||
register(provider: TProvider) {
|
||||
this.#providers.set(provider.provider, provider);
|
||||
this.logger.log(`Calendar provider [${provider.provider}] registered.`);
|
||||
}
|
||||
|
||||
unregister(provider: CalendarProvider) {
|
||||
unregister(provider: TProvider) {
|
||||
this.#providers.delete(provider.provider);
|
||||
this.logger.log(`Calendar provider [${provider.provider}] unregistered.`);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { CalendarProviderRequestError } from '../../../base';
|
||||
import { CalendarProvider } from './def';
|
||||
import {
|
||||
CalendarProvider,
|
||||
CalendarProviderEvent,
|
||||
CalendarProviderListCalendarsParams,
|
||||
CalendarProviderListEventsParams,
|
||||
CalendarProviderListEventsResult,
|
||||
CalendarProviderName,
|
||||
CalendarProviderTokens,
|
||||
CalendarProviderWatchParams,
|
||||
CalendarProviderWatchResult,
|
||||
} from './def';
|
||||
import { CalendarProviderName } from './factory';
|
||||
|
||||
export class CalendarSyncTokenInvalid extends Error {
|
||||
readonly code = 'calendar_sync_token_invalid';
|
||||
|
||||
@@ -14,9 +14,8 @@ export type {
|
||||
CalendarProviderWatchParams,
|
||||
CalendarProviderWatchResult,
|
||||
} from './def';
|
||||
export { CalendarProviderName } from './def';
|
||||
export { CalendarProvider } from './def';
|
||||
export { CalendarProviderFactory } from './factory';
|
||||
export { CalendarProviderFactory, CalendarProviderName } from './factory';
|
||||
export { CalendarSyncTokenInvalid, GoogleCalendarProvider } from './google';
|
||||
|
||||
export const CalendarProviders = [GoogleCalendarProvider, CalDAVProvider];
|
||||
|
||||
@@ -18,10 +18,10 @@ import {
|
||||
CalendarProvider,
|
||||
CalendarProviderEvent,
|
||||
CalendarProviderEventTime,
|
||||
CalendarProviderFactory,
|
||||
CalendarProviderName,
|
||||
CalendarSyncTokenInvalid,
|
||||
} from './providers';
|
||||
import { CalendarProviderFactory } from './providers';
|
||||
import type { LinkCalDAVAccountInput } from './types';
|
||||
|
||||
const TOKEN_REFRESH_SKEW_MS = 60 * 1000;
|
||||
@@ -35,7 +35,7 @@ export class CalendarService {
|
||||
|
||||
constructor(
|
||||
private readonly models: Models,
|
||||
private readonly providerFactory: CalendarProviderFactory,
|
||||
private readonly providerFactory: CalendarProviderFactory<CalendarProvider>,
|
||||
private readonly mutex: Mutex,
|
||||
private readonly config: Config,
|
||||
private readonly url: URLHelper
|
||||
@@ -105,11 +105,11 @@ export class CalendarService {
|
||||
const accessToken = accountTokens.accessToken;
|
||||
if (accessToken) {
|
||||
await Promise.allSettled(
|
||||
needToStopChannel.map(s => {
|
||||
needToStopChannel.map(async s => {
|
||||
if (!s.customChannelId || !s.customResourceId) {
|
||||
return Promise.resolve();
|
||||
return;
|
||||
}
|
||||
return provider.stopChannel?.({
|
||||
return await provider.stopChannel?.({
|
||||
accessToken,
|
||||
channelId: s.customChannelId,
|
||||
resourceId: s.customResourceId,
|
||||
@@ -654,8 +654,11 @@ export class CalendarService {
|
||||
}
|
||||
|
||||
const zone = time.timeZone ?? fallbackTimezone ?? 'UTC';
|
||||
if (!time.date) {
|
||||
throw new Error('Calendar provider returned all-day event without date');
|
||||
}
|
||||
return {
|
||||
date: this.convertDateToUtc(time.date!, zone),
|
||||
date: this.convertDateToUtc(time.date, zone),
|
||||
allDay: true,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ import {
|
||||
FileChunkSimilarity,
|
||||
Models,
|
||||
} from '../../../models';
|
||||
import { CopilotEmbeddingJob } from '../embedding';
|
||||
import { CopilotEmbeddingJob } from '../embedding/job';
|
||||
import { COPILOT_LOCKER, CopilotType } from '../resolver';
|
||||
import { ChatSessionService } from '../session';
|
||||
import { CopilotStorage } from '../storage';
|
||||
|
||||
@@ -15,7 +15,8 @@ import {
|
||||
ContextFile,
|
||||
Models,
|
||||
} from '../../../models';
|
||||
import { type EmbeddingClient, getEmbeddingClient } from '../embedding';
|
||||
import { getEmbeddingClient } from '../embedding/client';
|
||||
import type { EmbeddingClient } from '../embedding/types';
|
||||
import { ContextSession } from './session';
|
||||
|
||||
const CONTEXT_SESSION_KEY = 'context-session';
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
FileChunkSimilarity,
|
||||
Models,
|
||||
} from '../../../models';
|
||||
import { EmbeddingClient } from '../embedding';
|
||||
import { EmbeddingClient } from '../embedding/types';
|
||||
|
||||
export class ContextSession implements AsyncDisposable {
|
||||
constructor(
|
||||
|
||||
@@ -47,14 +47,14 @@ import {
|
||||
} from '../../base';
|
||||
import { ServerFeature, ServerService } from '../../core';
|
||||
import { CurrentUser, Public } from '../../core/auth';
|
||||
import { CopilotContextService } from './context';
|
||||
import { CopilotContextService } from './context/service';
|
||||
import { CopilotProviderFactory } from './providers/factory';
|
||||
import type { CopilotProvider } from './providers/provider';
|
||||
import {
|
||||
CopilotProvider,
|
||||
CopilotProviderFactory,
|
||||
ModelInputType,
|
||||
ModelOutputType,
|
||||
StreamObject,
|
||||
} from './providers';
|
||||
type StreamObject,
|
||||
} from './providers/types';
|
||||
import { StreamObjectParser } from './providers/utils';
|
||||
import { ChatSession, ChatSessionService } from './session';
|
||||
import { CopilotStorage } from './storage';
|
||||
@@ -560,7 +560,7 @@ export class CopilotController implements BeforeApplicationShutdown {
|
||||
status: data.status,
|
||||
id: data.node.id,
|
||||
type: data.node.config.nodeType,
|
||||
} as any,
|
||||
},
|
||||
};
|
||||
}
|
||||
})
|
||||
|
||||
@@ -12,14 +12,14 @@ import {
|
||||
Embedding,
|
||||
EMBEDDING_DIMENSIONS,
|
||||
} from '../../../models';
|
||||
import { PromptService } from '../prompt';
|
||||
import { PromptService } from '../prompt/service';
|
||||
import { CopilotProviderFactory } from '../providers/factory';
|
||||
import type { CopilotProvider } from '../providers/provider';
|
||||
import {
|
||||
type CopilotProvider,
|
||||
CopilotProviderFactory,
|
||||
type ModelFullConditions,
|
||||
ModelInputType,
|
||||
ModelOutputType,
|
||||
} from '../providers';
|
||||
} from '../providers/types';
|
||||
import { EmbeddingClient, type ReRankResult } from './types';
|
||||
|
||||
const EMBEDDING_MODEL = 'gemini-embedding-001';
|
||||
|
||||
@@ -8,7 +8,7 @@ import { DocReader, DocWriter } from '../../../core/doc';
|
||||
import { AccessController } from '../../../core/permission';
|
||||
import { clearEmbeddingChunk } from '../../../models';
|
||||
import { IndexerService } from '../../indexer';
|
||||
import { CopilotContextService } from '../context';
|
||||
import { CopilotContextService } from '../context/service';
|
||||
|
||||
@Injectable()
|
||||
export class WorkspaceMcpProvider {
|
||||
|
||||
@@ -4,7 +4,11 @@ import { AiPrompt } from '@prisma/client';
|
||||
import Mustache from 'mustache';
|
||||
|
||||
import { getTokenEncoder } from '../../../native';
|
||||
import { PromptConfig, PromptMessage, PromptParams } from '../providers';
|
||||
import type {
|
||||
PromptConfig,
|
||||
PromptMessage,
|
||||
PromptParams,
|
||||
} from '../providers/types';
|
||||
|
||||
// disable escaping
|
||||
Mustache.escape = (text: string) => text;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { AiPrompt, PrismaClient } from '@prisma/client';
|
||||
|
||||
import { PromptConfig, PromptMessage } from '../providers';
|
||||
import type { PromptConfig, PromptMessage } from '../providers/types';
|
||||
|
||||
type Prompt = Omit<
|
||||
AiPrompt,
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
PromptConfigSchema,
|
||||
PromptMessage,
|
||||
PromptMessageSchema,
|
||||
} from '../providers';
|
||||
} from '../providers/types';
|
||||
import { ChatPrompt } from './chat-prompt';
|
||||
import {
|
||||
CopilotPromptScenario,
|
||||
|
||||
@@ -13,8 +13,8 @@ import { DocReader, DocWriter } from '../../../core/doc';
|
||||
import { AccessController } from '../../../core/permission';
|
||||
import { Models } from '../../../models';
|
||||
import { IndexerService } from '../../indexer';
|
||||
import { CopilotContextService } from '../context';
|
||||
import { PromptService } from '../prompt';
|
||||
import { CopilotContextService } from '../context/service';
|
||||
import { PromptService } from '../prompt/service';
|
||||
import {
|
||||
buildBlobContentGetter,
|
||||
buildContentGetter,
|
||||
|
||||
@@ -42,9 +42,9 @@ import { AccessController, DocAction } from '../../core/permission';
|
||||
import { UserType } from '../../core/user';
|
||||
import type { ListSessionOptions, UpdateChatSession } from '../../models';
|
||||
import { CopilotCronJobs } from './cron';
|
||||
import { PromptService } from './prompt';
|
||||
import { PromptMessage, StreamObject } from './providers';
|
||||
import { PromptService } from './prompt/service';
|
||||
import { CopilotProviderFactory } from './providers/factory';
|
||||
import type { PromptMessage, StreamObject } from './providers/types';
|
||||
import { ChatSessionService } from './session';
|
||||
import { CopilotStorage } from './storage';
|
||||
import { type ChatHistory, type ChatMessage, SubmittedMessage } from './types';
|
||||
|
||||
@@ -28,13 +28,14 @@ import {
|
||||
import { SubscriptionService } from '../payment/service';
|
||||
import { SubscriptionPlan, SubscriptionStatus } from '../payment/types';
|
||||
import { ChatMessageCache } from './message';
|
||||
import { ChatPrompt, PromptService } from './prompt';
|
||||
import { ChatPrompt } from './prompt/chat-prompt';
|
||||
import { PromptService } from './prompt/service';
|
||||
import { CopilotProviderFactory } from './providers/factory';
|
||||
import {
|
||||
CopilotProviderFactory,
|
||||
ModelOutputType,
|
||||
PromptMessage,
|
||||
PromptParams,
|
||||
} from './providers';
|
||||
type PromptMessage,
|
||||
type PromptParams,
|
||||
} from './providers/types';
|
||||
import {
|
||||
type ChatHistory,
|
||||
type ChatMessage,
|
||||
@@ -322,7 +323,7 @@ export class ChatSessionService {
|
||||
|
||||
private stripNullBytes(value?: string | null): string {
|
||||
if (!value) return '';
|
||||
return value.replace(/\u0000/g, '');
|
||||
return value.replaceAll('\0', '');
|
||||
}
|
||||
|
||||
private isNullByteError(error: unknown): boolean {
|
||||
|
||||
@@ -3,9 +3,8 @@ import { tool } from 'ai';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { AccessController } from '../../../core/permission';
|
||||
import type { ContextSession } from '../context/session';
|
||||
import type { CopilotChatOptions } from '../providers';
|
||||
import { toolError } from './error';
|
||||
import type { ContextSession, CopilotChatOptions } from './types';
|
||||
|
||||
const logger = new Logger('ContextBlobReadTool');
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ import { Logger } from '@nestjs/common';
|
||||
import { tool } from 'ai';
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { PromptService } from '../prompt';
|
||||
import type { CopilotProviderFactory } from '../providers';
|
||||
import { toolError } from './error';
|
||||
import type { CopilotProviderFactory, PromptService } from './types';
|
||||
|
||||
const logger = new Logger('CodeArtifactTool');
|
||||
/**
|
||||
* A copilot tool that produces a completely self-contained HTML artifact.
|
||||
|
||||
@@ -2,9 +2,8 @@ import { Logger } from '@nestjs/common';
|
||||
import { tool } from 'ai';
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { PromptService } from '../prompt';
|
||||
import type { CopilotProviderFactory } from '../providers';
|
||||
import { toolError } from './error';
|
||||
import type { CopilotProviderFactory, PromptService } from './types';
|
||||
|
||||
const logger = new Logger('ConversationSummaryTool');
|
||||
|
||||
|
||||
@@ -2,9 +2,8 @@ import { Logger } from '@nestjs/common';
|
||||
import { tool } from 'ai';
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { PromptService } from '../prompt';
|
||||
import type { CopilotProviderFactory } from '../providers';
|
||||
import { toolError } from './error';
|
||||
import type { CopilotProviderFactory, PromptService } from './types';
|
||||
|
||||
const logger = new Logger('DocComposeTool');
|
||||
|
||||
|
||||
@@ -3,8 +3,11 @@ import { z } from 'zod';
|
||||
|
||||
import { DocReader } from '../../../core/doc';
|
||||
import { AccessController } from '../../../core/permission';
|
||||
import { type PromptService } from '../prompt';
|
||||
import type { CopilotChatOptions, CopilotProviderFactory } from '../providers';
|
||||
import type {
|
||||
CopilotChatOptions,
|
||||
CopilotProviderFactory,
|
||||
PromptService,
|
||||
} from './types';
|
||||
|
||||
const CodeEditSchema = z
|
||||
.array(
|
||||
|
||||
@@ -3,8 +3,8 @@ import { z } from 'zod';
|
||||
|
||||
import type { AccessController } from '../../../core/permission';
|
||||
import type { IndexerService, SearchDoc } from '../../indexer';
|
||||
import type { CopilotChatOptions } from '../providers';
|
||||
import { toolError } from './error';
|
||||
import type { CopilotChatOptions } from './types';
|
||||
|
||||
export const buildDocKeywordSearchGetter = (
|
||||
ac: AccessController,
|
||||
|
||||
@@ -5,8 +5,8 @@ import { z } from 'zod';
|
||||
import { DocReader } from '../../../core/doc';
|
||||
import { AccessController } from '../../../core/permission';
|
||||
import { Models, publicUserSelect } from '../../../models';
|
||||
import type { CopilotChatOptions } from '../providers';
|
||||
import { toolError } from './error';
|
||||
import type { CopilotChatOptions } from './types';
|
||||
|
||||
const logger = new Logger('DocReadTool');
|
||||
|
||||
|
||||
@@ -8,10 +8,12 @@ import {
|
||||
clearEmbeddingChunk,
|
||||
type Models,
|
||||
} from '../../../models';
|
||||
import type { CopilotContextService } from '../context';
|
||||
import type { ContextSession } from '../context/session';
|
||||
import type { CopilotChatOptions } from '../providers';
|
||||
import { toolError } from './error';
|
||||
import type {
|
||||
ContextSession,
|
||||
CopilotChatOptions,
|
||||
CopilotContextService,
|
||||
} from './types';
|
||||
|
||||
export const buildDocSearchGetter = (
|
||||
ac: AccessController,
|
||||
|
||||
@@ -4,8 +4,8 @@ import { z } from 'zod';
|
||||
|
||||
import { DocWriter } from '../../../core/doc';
|
||||
import { AccessController } from '../../../core/permission';
|
||||
import type { CopilotChatOptions } from '../providers';
|
||||
import { toolError } from './error';
|
||||
import type { CopilotChatOptions } from './types';
|
||||
|
||||
const logger = new Logger('DocWriteTool');
|
||||
|
||||
|
||||
@@ -2,9 +2,8 @@ import { Logger } from '@nestjs/common';
|
||||
import { tool } from 'ai';
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { PromptService } from '../prompt';
|
||||
import type { CopilotProviderFactory } from '../providers';
|
||||
import { toolError } from './error';
|
||||
import type { CopilotProviderFactory, PromptService } from './types';
|
||||
|
||||
const logger = new Logger('SectionEditTool');
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
export type { CopilotContextService } from '../context/service';
|
||||
export type { ContextSession } from '../context/session';
|
||||
export type { PromptService } from '../prompt/service';
|
||||
export type { CopilotProviderFactory } from '../providers/factory';
|
||||
export type { CopilotChatOptions } from '../providers/types';
|
||||
@@ -125,6 +125,7 @@ export class CopilotTranscriptionResolver {
|
||||
user.id,
|
||||
workspaceId,
|
||||
blobId,
|
||||
// eslint-disable-next-line @typescript-eslint/await-thenable
|
||||
await Promise.all(allBlobs)
|
||||
);
|
||||
|
||||
|
||||
@@ -15,14 +15,10 @@ import {
|
||||
sniffMime,
|
||||
} from '../../../base';
|
||||
import { Models } from '../../../models';
|
||||
import { PromptService } from '../prompt';
|
||||
import {
|
||||
CopilotProvider,
|
||||
CopilotProviderFactory,
|
||||
CopilotProviderType,
|
||||
ModelOutputType,
|
||||
PromptMessage,
|
||||
} from '../providers';
|
||||
import { PromptService } from '../prompt/service';
|
||||
import type { CopilotProvider, PromptMessage } from '../providers';
|
||||
import { CopilotProviderFactory } from '../providers/factory';
|
||||
import { CopilotProviderType, ModelOutputType } from '../providers/types';
|
||||
import { CopilotStorage } from '../storage';
|
||||
import {
|
||||
AudioBlobInfos,
|
||||
@@ -171,7 +167,7 @@ export class CopilotTranscriptionService {
|
||||
if (payload.success) {
|
||||
let { url, mimeType, infos } = payload.data;
|
||||
infos = infos || [];
|
||||
if (url && mimeType && !infos.find(i => i.url === url)) {
|
||||
if (url && mimeType && !infos.some(i => i.url === url)) {
|
||||
infos.push({ url, mimeType });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { ChatPrompt } from './prompt';
|
||||
import { PromptMessageSchema, PureMessageSchema } from './providers';
|
||||
import type { ChatPrompt } from './prompt/chat-prompt';
|
||||
import { PromptMessageSchema, PureMessageSchema } from './providers/types';
|
||||
|
||||
const takeFirst = (v: unknown) => (Array.isArray(v) ? v[0] : v);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Readable } from 'node:stream';
|
||||
import type { Request } from 'express';
|
||||
|
||||
import { OneMB, readBufferWithLimit } from '../../base';
|
||||
import type { PromptTools } from './providers';
|
||||
import type { PromptTools } from './providers/types';
|
||||
import type { ToolsConfig } from './types';
|
||||
|
||||
export const MAX_EMBEDDABLE_SIZE = 50 * OneMB;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { fileURLToPath } from 'node:url';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import Piscina from 'piscina';
|
||||
|
||||
import { CopilotChatOptions } from '../providers';
|
||||
import type { CopilotChatOptions } from '../providers/types';
|
||||
import type { NodeExecuteResult, NodeExecutor } from './executor';
|
||||
import { getWorkflowExecutor, NodeExecuteState } from './executor';
|
||||
import type {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { CopilotChatOptions } from '../providers';
|
||||
import type { CopilotChatOptions } from '../providers/types';
|
||||
import { WorkflowGraphList } from './graph';
|
||||
import { WorkflowNode } from './node';
|
||||
import type { WorkflowGraph, WorkflowGraphInstances } from './types';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
|
||||
import { CopilotChatOptions } from '../providers';
|
||||
import type { CopilotChatOptions } from '../providers/types';
|
||||
import { NodeExecuteState } from './executor';
|
||||
import { WorkflowNode } from './node';
|
||||
import type { WorkflowGraphInstances, WorkflowNodeState } from './types';
|
||||
|
||||
@@ -132,6 +132,10 @@ export class IndexerJob {
|
||||
indexed: true,
|
||||
});
|
||||
}
|
||||
if (!missingDocIds.length && !deletedDocIds.length) {
|
||||
this.logger.verbose(`workspace ${workspaceId} is already indexed`);
|
||||
return;
|
||||
}
|
||||
this.logger.log(
|
||||
`indexed workspace ${workspaceId} with ${missingDocIds.length} missing docs and ${deletedDocIds.length} deleted docs`
|
||||
);
|
||||
|
||||
@@ -132,10 +132,11 @@ export class AppleOAuthProvider extends OAuthProvider {
|
||||
{ method: 'GET' },
|
||||
{ treatServerErrorAsInvalid: true }
|
||||
);
|
||||
const idToken = tokens.idToken;
|
||||
|
||||
const payload = await new Promise<JwtPayload>((resolve, reject) => {
|
||||
jwt.verify(
|
||||
tokens.idToken!,
|
||||
idToken,
|
||||
(header, callback) => {
|
||||
const key = keys.find(key => key.kid === header.kid);
|
||||
if (!key) {
|
||||
|
||||
@@ -29,6 +29,36 @@ const SHOULD_MANUAL_REDIRECT =
|
||||
BUILD_CONFIG.isAndroid || BUILD_CONFIG.isIOS || BUILD_CONFIG.isElectron;
|
||||
const UPLOAD_REQUEST_TIMEOUT = 0;
|
||||
|
||||
function toStrictArrayBuffer(
|
||||
data: ArrayBuffer | ArrayBufferLike | ArrayBufferView
|
||||
): ArrayBuffer {
|
||||
if (data instanceof ArrayBuffer) {
|
||||
return data;
|
||||
}
|
||||
|
||||
if (ArrayBuffer.isView(data)) {
|
||||
if (data.buffer instanceof ArrayBuffer) {
|
||||
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
||||
return data.buffer;
|
||||
}
|
||||
return data.buffer.slice(
|
||||
data.byteOffset,
|
||||
data.byteOffset + data.byteLength
|
||||
);
|
||||
}
|
||||
|
||||
const bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
||||
const copy = new Uint8Array(bytes.byteLength);
|
||||
copy.set(bytes);
|
||||
return copy.buffer;
|
||||
}
|
||||
|
||||
const bytes = new Uint8Array(data);
|
||||
const copy = new Uint8Array(bytes.byteLength);
|
||||
copy.set(bytes);
|
||||
return copy.buffer;
|
||||
}
|
||||
|
||||
export class CloudBlobStorage extends BlobStorageBase {
|
||||
static readonly identifier = 'CloudBlobStorage';
|
||||
override readonly isReadonly = false;
|
||||
@@ -127,8 +157,11 @@ export class CloudBlobStorage extends BlobStorageBase {
|
||||
|
||||
if (upload.method === BlobUploadMethod.PRESIGNED) {
|
||||
try {
|
||||
if (!upload.uploadUrl) {
|
||||
throw new Error('Missing upload URL for presigned upload.');
|
||||
}
|
||||
await this.uploadViaPresigned(
|
||||
upload.uploadUrl!,
|
||||
upload.uploadUrl,
|
||||
upload.headers,
|
||||
blob.data,
|
||||
signal
|
||||
@@ -143,15 +176,20 @@ export class CloudBlobStorage extends BlobStorageBase {
|
||||
|
||||
if (upload.method === BlobUploadMethod.MULTIPART) {
|
||||
try {
|
||||
if (!upload.uploadId || !upload.partSize) {
|
||||
throw new Error(
|
||||
'Missing upload ID or part size for multipart upload.'
|
||||
);
|
||||
}
|
||||
const parts = await this.uploadViaMultipart(
|
||||
blob.key,
|
||||
upload.uploadId!,
|
||||
upload.partSize!,
|
||||
upload.uploadId,
|
||||
upload.partSize,
|
||||
blob.data,
|
||||
upload.uploadedParts,
|
||||
signal
|
||||
);
|
||||
await this.completeUpload(blob.key, upload.uploadId!, parts, signal);
|
||||
await this.completeUpload(blob.key, upload.uploadId, parts, signal);
|
||||
return;
|
||||
} catch {
|
||||
if (upload.uploadId) {
|
||||
@@ -216,7 +254,9 @@ export class CloudBlobStorage extends BlobStorageBase {
|
||||
query: setBlobMutation,
|
||||
variables: {
|
||||
workspaceId: this.options.id,
|
||||
blob: new File([blob.data], blob.key, { type: blob.mime }),
|
||||
blob: new File([toStrictArrayBuffer(blob.data)], blob.key, {
|
||||
type: blob.mime,
|
||||
}),
|
||||
},
|
||||
context: { signal },
|
||||
timeout: UPLOAD_REQUEST_TIMEOUT,
|
||||
@@ -232,7 +272,7 @@ export class CloudBlobStorage extends BlobStorageBase {
|
||||
const res = await this.fetchWithTimeout(uploadUrl, {
|
||||
method: 'PUT',
|
||||
headers: headers ?? undefined,
|
||||
body: data,
|
||||
body: toStrictArrayBuffer(data),
|
||||
signal,
|
||||
timeout: UPLOAD_REQUEST_TIMEOUT,
|
||||
});
|
||||
@@ -275,7 +315,7 @@ export class CloudBlobStorage extends BlobStorageBase {
|
||||
{
|
||||
method: 'PUT',
|
||||
headers: part.workspace.blobUploadPartUrl.headers ?? undefined,
|
||||
body: chunk,
|
||||
body: toStrictArrayBuffer(chunk),
|
||||
signal,
|
||||
timeout: UPLOAD_REQUEST_TIMEOUT,
|
||||
}
|
||||
|
||||
@@ -141,10 +141,10 @@ export class CloudIndexerStorage extends IndexerStorageBase {
|
||||
}
|
||||
|
||||
override async refreshIfNeed(): Promise<void> {
|
||||
return Promise.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
override async indexVersion(): Promise<number> {
|
||||
return Promise.resolve(1);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,6 +222,6 @@ export class IndexedDBIndexerStorage extends IndexerStorageBase {
|
||||
// Get the current indexer version
|
||||
// increase this number to re-index all docs
|
||||
async indexVersion(): Promise<number> {
|
||||
return Promise.resolve(1);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { merge, Observable, of, Subject } from 'rxjs';
|
||||
import type { Observable } from 'rxjs';
|
||||
import { merge, of, Subject } from 'rxjs';
|
||||
import { filter, throttleTime } from 'rxjs/operators';
|
||||
|
||||
import { share } from '../../../connection';
|
||||
@@ -194,9 +195,9 @@ export class SqliteIndexerStorage extends IndexerStorageBase {
|
||||
const schema = IndexerSchema[table];
|
||||
for (const [field, values] of document.fields) {
|
||||
const fieldSchema = schema[field];
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error -- IndexerSchema uses runtime-keyed fields from each table schema.
|
||||
const shouldIndex = fieldSchema.index !== false;
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error -- IndexerSchema uses runtime-keyed fields from each table schema.
|
||||
const shouldStore = fieldSchema.store !== false;
|
||||
|
||||
if (!shouldStore && !shouldIndex) continue;
|
||||
|
||||
@@ -86,9 +86,9 @@ export class DummyIndexerStorage extends IndexerStorageBase {
|
||||
return Promise.resolve();
|
||||
}
|
||||
override async refreshIfNeed(): Promise<void> {
|
||||
return Promise.resolve();
|
||||
return;
|
||||
}
|
||||
override async indexVersion(): Promise<number> {
|
||||
return Promise.resolve(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,6 +190,7 @@ export class BlobSyncImpl implements BlobSync {
|
||||
): Promise<void> {
|
||||
return Promise.race([
|
||||
Promise.all(
|
||||
// eslint-disable-next-line @typescript-eslint/await-thenable
|
||||
peerId
|
||||
? [this.fullDownloadPeer(peerId)]
|
||||
: this.peers.map(p => this.fullDownloadPeer(p.peerId))
|
||||
|
||||
@@ -125,8 +125,8 @@ export class TelemetryManager {
|
||||
|
||||
private mergeContext(event: TelemetryEvent): TelemetryEvent {
|
||||
const mergedUserProps = {
|
||||
...(this.context.userProperties ?? {}),
|
||||
...(event.userProperties ?? {}),
|
||||
...this.context.userProperties,
|
||||
...event.userProperties,
|
||||
};
|
||||
|
||||
const mergedContext = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Buffer } from 'node:buffer';
|
||||
import type { Buffer } from 'node:buffer';
|
||||
import { stringify as stringifyQuery } from 'node:querystring';
|
||||
import { Readable } from 'node:stream';
|
||||
import type { Readable } from 'node:stream';
|
||||
|
||||
import aws4 from 'aws4';
|
||||
import { XMLParser } from 'fast-xml-parser';
|
||||
@@ -180,16 +180,16 @@ export function parseListPartsXml(xml: string): ParsedListParts {
|
||||
function buildEndpoint(config: S3CompatConfig) {
|
||||
const url = new URL(config.endpoint);
|
||||
if (config.forcePathStyle) {
|
||||
const segments = url.pathname.split('/').filter(Boolean);
|
||||
if (segments[0] !== config.bucket) {
|
||||
const firstSegment = url.pathname.split('/').find(Boolean);
|
||||
if (firstSegment !== config.bucket) {
|
||||
url.pathname = joinPath(url.pathname, config.bucket);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
const pathSegments = url.pathname.split('/').filter(Boolean);
|
||||
const firstSegment = url.pathname.split('/').find(Boolean);
|
||||
const hostHasBucket = url.hostname.startsWith(`${config.bucket}.`);
|
||||
const pathHasBucket = pathSegments[0] === config.bucket;
|
||||
const pathHasBucket = firstSegment === config.bucket;
|
||||
if (!hostHasBucket && !pathHasBucket) {
|
||||
url.hostname = `${config.bucket}.${url.hostname}`;
|
||||
}
|
||||
@@ -297,7 +297,7 @@ export class S3Compat implements S3CompatClient {
|
||||
const expiresInSeconds = this.presignConfig.expiresInSeconds;
|
||||
const path = this.buildObjectPath(key);
|
||||
const queryString = buildQuery({
|
||||
...(query ?? {}),
|
||||
...query,
|
||||
'X-Amz-Expires': expiresInSeconds,
|
||||
});
|
||||
const requestPath = queryString ? `${path}?${queryString}` : path;
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
"zod": "^3.25.76"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/react": "^16.3.2",
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
@@ -67,7 +68,8 @@
|
||||
"shadcn-ui": "^0.9.5",
|
||||
"tailwind-merge": "^3.4.0",
|
||||
"tailwindcss": "^4.1.17",
|
||||
"tailwindcss-animate": "^1.0.7"
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"vitest": "^3.2.4"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "affine bundle",
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
import { toast } from 'sonner';
|
||||
import { SWRConfig } from 'swr';
|
||||
|
||||
import { ThemeProvider } from './components/theme-provider';
|
||||
import { TooltipProvider } from './components/ui/tooltip';
|
||||
import { isAdmin, useCurrentUser, useServerConfig } from './modules/common';
|
||||
import { Layout } from './modules/layout';
|
||||
@@ -94,58 +95,55 @@ function RootRoutes() {
|
||||
|
||||
export const App = () => {
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<SWRConfig
|
||||
value={{
|
||||
revalidateOnFocus: false,
|
||||
revalidateOnMount: false,
|
||||
}}
|
||||
>
|
||||
<BrowserRouter basename={environment.subPath}>
|
||||
<Routes>
|
||||
<Route path={ROUTES.admin.index} element={<RootRoutes />}>
|
||||
<Route path={ROUTES.admin.auth} element={<Auth />} />
|
||||
<Route path={ROUTES.admin.setup} element={<Setup />} />
|
||||
<Route element={<AuthenticatedRoutes />}>
|
||||
<Route
|
||||
path={ROUTES.admin.dashboard}
|
||||
element={
|
||||
environment.isSelfHosted ? (
|
||||
<Navigate to={ROUTES.admin.accounts} replace />
|
||||
) : (
|
||||
<Dashboard />
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Route path={ROUTES.admin.accounts} element={<Accounts />} />
|
||||
<Route
|
||||
path={ROUTES.admin.workspaces}
|
||||
element={
|
||||
environment.isSelfHosted ? (
|
||||
<Navigate to={ROUTES.admin.accounts} replace />
|
||||
) : (
|
||||
<Workspaces />
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Route path={`${ROUTES.admin.queue}/*`} element={<Queue />} />
|
||||
<Route path={ROUTES.admin.ai} element={<AI />} />
|
||||
<Route path={ROUTES.admin.about} element={<About />} />
|
||||
<Route
|
||||
path={ROUTES.admin.settings.index}
|
||||
element={<Settings />}
|
||||
>
|
||||
<ThemeProvider>
|
||||
<TooltipProvider>
|
||||
<SWRConfig
|
||||
value={{
|
||||
revalidateOnFocus: false,
|
||||
revalidateOnMount: false,
|
||||
}}
|
||||
>
|
||||
<BrowserRouter basename={environment.subPath}>
|
||||
<Routes>
|
||||
<Route path={ROUTES.admin.index} element={<RootRoutes />}>
|
||||
<Route path={ROUTES.admin.auth} element={<Auth />} />
|
||||
<Route path={ROUTES.admin.setup} element={<Setup />} />
|
||||
<Route element={<AuthenticatedRoutes />}>
|
||||
<Route
|
||||
path={ROUTES.admin.settings.module}
|
||||
path={ROUTES.admin.dashboard}
|
||||
element={
|
||||
environment.isSelfHosted ? (
|
||||
<Navigate to={ROUTES.admin.accounts} replace />
|
||||
) : (
|
||||
<Dashboard />
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Route path={ROUTES.admin.accounts} element={<Accounts />} />
|
||||
<Route
|
||||
path={ROUTES.admin.workspaces}
|
||||
element={
|
||||
environment.isSelfHosted ? (
|
||||
<Navigate to={ROUTES.admin.accounts} replace />
|
||||
) : (
|
||||
<Workspaces />
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Route path={`${ROUTES.admin.queue}/*`} element={<Queue />} />
|
||||
<Route path={ROUTES.admin.ai} element={<AI />} />
|
||||
<Route path={ROUTES.admin.about} element={<About />} />
|
||||
<Route
|
||||
path={ROUTES.admin.settings.index}
|
||||
element={<Settings />}
|
||||
/>
|
||||
</Route>
|
||||
</Route>
|
||||
</Route>
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
</SWRConfig>
|
||||
<Toaster />
|
||||
</TooltipProvider>
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
</SWRConfig>
|
||||
<Toaster />
|
||||
</TooltipProvider>
|
||||
</ThemeProvider>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -39,7 +39,7 @@ export const ConfirmDialog = ({
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:w-[460px]">
|
||||
<DialogContent className="sm:max-w-[460px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="leading-7">{title}</DialogTitle>
|
||||
<DialogDescription className="leading-6">
|
||||
@@ -48,13 +48,19 @@ export const ConfirmDialog = ({
|
||||
</DialogHeader>
|
||||
<DialogFooter className="mt-6">
|
||||
<div className="flex justify-end gap-2 items-center w-full">
|
||||
<Button type="button" onClick={handleClose} variant="outline">
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleClose}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
>
|
||||
<span>{cancelText}</span>
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={onConfirm}
|
||||
variant={confirmButtonVariant}
|
||||
size="sm"
|
||||
>
|
||||
<span>{confirmText}</span>
|
||||
</Button>
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* @vitest-environment happy-dom
|
||||
*/
|
||||
import type { ColumnDef } from '@tanstack/react-table';
|
||||
import { cleanup, render, screen } from '@testing-library/react';
|
||||
import { afterEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
import { SharedDataTable } from './data-table';
|
||||
|
||||
const { DataTablePaginationMock } = vi.hoisted(() => ({
|
||||
DataTablePaginationMock: vi.fn(({ disabled }: { disabled?: boolean }) => (
|
||||
<div data-disabled={disabled ? 'true' : 'false'} data-testid="pagination" />
|
||||
)),
|
||||
}));
|
||||
|
||||
vi.mock('./data-table-pagination', () => ({
|
||||
DataTablePagination: DataTablePaginationMock,
|
||||
}));
|
||||
|
||||
type Row = { id: string; name: string };
|
||||
|
||||
const columns: ColumnDef<Row>[] = [
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: 'Name',
|
||||
cell: ({ row }) => row.original.name,
|
||||
},
|
||||
];
|
||||
|
||||
describe('SharedDataTable', () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
DataTablePaginationMock.mockClear();
|
||||
});
|
||||
|
||||
test('renders token-aligned table shell and row data', () => {
|
||||
const { container } = render(
|
||||
<SharedDataTable
|
||||
columns={columns}
|
||||
data={[{ id: '1', name: 'Alice' }]}
|
||||
totalCount={1}
|
||||
pagination={{ pageIndex: 0, pageSize: 10 }}
|
||||
onPaginationChange={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.queryByText('Alice')).not.toBeNull();
|
||||
|
||||
const shell = container.querySelector('.rounded-xl');
|
||||
expect(shell).not.toBeNull();
|
||||
expect(shell?.className).toContain('border-border');
|
||||
expect(shell?.className).toContain('bg-card');
|
||||
expect(shell?.className).toContain('shadow-1');
|
||||
});
|
||||
|
||||
test('shows loading overlay and disables pagination while loading', () => {
|
||||
render(
|
||||
<SharedDataTable
|
||||
columns={columns}
|
||||
data={[{ id: '1', name: 'Alice' }]}
|
||||
totalCount={1}
|
||||
pagination={{ pageIndex: 0, pageSize: 10 }}
|
||||
onPaginationChange={vi.fn()}
|
||||
loading={true}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.queryByText('Loading...')).not.toBeNull();
|
||||
expect(screen.getByTestId('pagination').dataset.disabled).toBe('true');
|
||||
});
|
||||
|
||||
test('renders empty state when there is no data', () => {
|
||||
render(
|
||||
<SharedDataTable
|
||||
columns={columns}
|
||||
data={[]}
|
||||
totalCount={0}
|
||||
pagination={{ pageIndex: 0, pageSize: 10 }}
|
||||
onPaginationChange={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.queryByText('No results.')).not.toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -21,6 +21,8 @@ import { type ReactNode, useEffect, useState } from 'react';
|
||||
|
||||
import { DataTablePagination } from './data-table-pagination';
|
||||
|
||||
const DEFAULT_RESET_FILTERS_DEPS: unknown[] = [];
|
||||
|
||||
interface DataTableProps<TData, TValue> {
|
||||
columns: ColumnDef<TData, TValue>[];
|
||||
data: TData[];
|
||||
@@ -58,7 +60,7 @@ export function SharedDataTable<TData extends { id: string }, TValue>({
|
||||
rowSelection,
|
||||
onRowSelectionChange,
|
||||
renderToolbar,
|
||||
resetFiltersDeps = [],
|
||||
resetFiltersDeps = DEFAULT_RESET_FILTERS_DEPS,
|
||||
}: DataTableProps<TData, TValue>) {
|
||||
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
||||
|
||||
@@ -66,6 +68,7 @@ export function SharedDataTable<TData extends { id: string }, TValue>({
|
||||
setColumnFilters([]);
|
||||
}, [resetFiltersDeps]);
|
||||
|
||||
// eslint-disable-next-line react-hooks/incompatible-library
|
||||
const table = useReactTable({
|
||||
data,
|
||||
columns,
|
||||
@@ -87,13 +90,13 @@ export function SharedDataTable<TData extends { id: string }, TValue>({
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4 py-5 px-6 h-full overflow-auto relative">
|
||||
<div className="relative flex h-full flex-col gap-4 overflow-auto px-6 py-5">
|
||||
{renderToolbar?.(table)}
|
||||
<div className="rounded-md border h-full flex flex-col overflow-auto relative">
|
||||
<div className="relative flex h-full flex-col overflow-auto rounded-xl border border-border/60 bg-card shadow-1">
|
||||
{loading ? (
|
||||
<div className="absolute inset-0 z-10 bg-gray-50/70 backdrop-blur-[1px] flex flex-col items-center justify-center gap-2 text-sm text-gray-600">
|
||||
<div className="absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/75 text-sm text-muted-foreground backdrop-blur-[1px]">
|
||||
<svg
|
||||
className="h-5 w-5 animate-spin text-gray-500"
|
||||
className="h-5 w-5 animate-spin text-primary"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
@@ -118,7 +121,10 @@ export function SharedDataTable<TData extends { id: string }, TValue>({
|
||||
<Table>
|
||||
<TableHeader>
|
||||
{table.getHeaderGroups().map(headerGroup => (
|
||||
<TableRow key={headerGroup.id} className="flex items-center">
|
||||
<TableRow
|
||||
key={headerGroup.id}
|
||||
className="flex items-center bg-muted/40"
|
||||
>
|
||||
{headerGroup.headers.map(header => {
|
||||
// Use meta.className if available, otherwise default to flex-1
|
||||
const meta = header.column.columnDef.meta as
|
||||
@@ -153,7 +159,7 @@ export function SharedDataTable<TData extends { id: string }, TValue>({
|
||||
<TableRow
|
||||
key={row.id}
|
||||
data-state={row.getIsSelected() && 'selected'}
|
||||
className="flex items-center"
|
||||
className="flex items-center bg-card"
|
||||
>
|
||||
{row.getVisibleCells().map(cell => {
|
||||
const meta = cell.column.columnDef.meta as
|
||||
|
||||
@@ -3,7 +3,6 @@ import { Label } from '@affine/admin/components/ui/label';
|
||||
import { Separator } from '@affine/admin/components/ui/separator';
|
||||
import { Switch } from '@affine/admin/components/ui/switch';
|
||||
import type { FeatureType } from '@affine/graphql';
|
||||
import { cssVarV2 } from '@toeverything/theme/v2';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { cn } from '../../utils';
|
||||
@@ -42,10 +41,7 @@ export const FeatureToggleList = ({
|
||||
|
||||
if (!features.length) {
|
||||
return (
|
||||
<div
|
||||
className={cn(className, 'px-3 py-2 text-xs')}
|
||||
style={{ color: cssVarV2('text/secondary') }}
|
||||
>
|
||||
<div className={cn(className, 'px-3 py-2 text-xs text-muted-foreground')}>
|
||||
No configurable features.
|
||||
</div>
|
||||
);
|
||||
@@ -57,10 +53,10 @@ export const FeatureToggleList = ({
|
||||
<div key={feature}>
|
||||
<Label
|
||||
className={cn(
|
||||
'cursor-pointer',
|
||||
'cursor-pointer transition-colors duration-100',
|
||||
controlPosition === 'right'
|
||||
? 'flex items-center justify-between p-3 text-[15px] gap-2 font-medium leading-6 overflow-hidden'
|
||||
: 'flex items-center gap-2 px-3 py-2 text-sm'
|
||||
? 'flex items-center justify-between p-3 text-sm gap-2 font-medium leading-6 overflow-hidden hover:bg-muted/40'
|
||||
: 'flex items-center gap-2 px-3 py-2 text-sm hover:bg-muted/40'
|
||||
)}
|
||||
>
|
||||
{controlPosition === 'left' ? (
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @vitest-environment happy-dom
|
||||
*/
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { describe, expect, test, vi } from 'vitest';
|
||||
|
||||
const { nextThemeProviderMock } = vi.hoisted(() => ({
|
||||
nextThemeProviderMock: vi.fn(({ children }: { children?: any }) => (
|
||||
<div data-testid="next-theme-provider">{children}</div>
|
||||
)),
|
||||
}));
|
||||
|
||||
vi.mock('next-themes', () => ({
|
||||
ThemeProvider: nextThemeProviderMock,
|
||||
}));
|
||||
|
||||
import { ThemeProvider } from './theme-provider';
|
||||
|
||||
describe('Admin ThemeProvider', () => {
|
||||
test('uses the same dark/light/system behavior as main frontend', () => {
|
||||
render(
|
||||
<ThemeProvider>
|
||||
<div>content</div>
|
||||
</ThemeProvider>
|
||||
);
|
||||
|
||||
expect(screen.queryByText('content')).not.toBeNull();
|
||||
expect(nextThemeProviderMock).toHaveBeenCalledTimes(1);
|
||||
|
||||
const props = nextThemeProviderMock.mock.calls[0]?.[0] as any;
|
||||
expect(props?.themes).toEqual(['dark', 'light']);
|
||||
expect(props?.enableSystem).toBe(true);
|
||||
expect(props?.defaultTheme).toBe('system');
|
||||
});
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user