mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-06 03:49:56 +08:00
feat: native sync state (#14190)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added indexed clock management capabilities for documents, enabling
get, set, and clear operations across Android, iOS, Electron, and web
platforms.
* **Refactor**
* Improved storage architecture to dynamically select platform-specific
implementations (SQLite for Electron, IndexedDB for others).
* **Bug Fixes**
* Enhanced document operations to properly maintain and clean up indexer
synchronization state during document lifecycle changes.
<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -30,6 +30,9 @@ export const nbstoreHandlers: NativeDBApis = {
|
||||
deleteDoc: POOL.deleteDoc.bind(POOL),
|
||||
getDocClocks: POOL.getDocClocks.bind(POOL),
|
||||
getDocClock: POOL.getDocClock.bind(POOL),
|
||||
getDocIndexedClock: POOL.getDocIndexedClock.bind(POOL),
|
||||
setDocIndexedClock: POOL.setDocIndexedClock.bind(POOL),
|
||||
clearDocIndexedClock: POOL.clearDocIndexedClock.bind(POOL),
|
||||
getBlob: POOL.getBlob.bind(POOL),
|
||||
setBlob: POOL.setBlob.bind(POOL),
|
||||
deleteBlob: POOL.deleteBlob.bind(POOL),
|
||||
|
||||
@@ -127,6 +127,12 @@ const needRefererDomains = [
|
||||
/^(?:[a-zA-Z0-9-]+\.)*googlevideo\.com$/,
|
||||
];
|
||||
const defaultReferer = 'https://client.affine.local/';
|
||||
const affineDomains = [
|
||||
/^(?:[a-z0-9-]+\.)*usercontent\.affine\.pro$/i,
|
||||
/^(?:[a-z0-9-]+\.)*affine\.pro$/i,
|
||||
/^(?:[a-z0-9-]+\.)*affine\.fail$/i,
|
||||
/^(?:[a-z0-9-]+\.)*affine\.run$/i,
|
||||
];
|
||||
|
||||
function setHeader(
|
||||
headers: Record<string, string[]>,
|
||||
@@ -166,6 +172,17 @@ function ensureFrameAncestors(
|
||||
});
|
||||
}
|
||||
|
||||
function allowCors(headers: Record<string, string[]>) {
|
||||
// Signed blob URLs redirect to *.usercontent.affine.pro without CORS headers.
|
||||
setHeader(headers, 'Access-Control-Allow-Origin', '*');
|
||||
setHeader(headers, 'Access-Control-Allow-Methods', 'GET, HEAD, OPTIONS');
|
||||
setHeader(
|
||||
headers,
|
||||
'Access-Control-Allow-Headers',
|
||||
'*, Authorization, Content-Type, Range'
|
||||
);
|
||||
}
|
||||
|
||||
export function registerProtocol() {
|
||||
protocol.handle('assets', request => {
|
||||
return handleFileRequest(request);
|
||||
@@ -211,9 +228,9 @@ export function registerProtocol() {
|
||||
}
|
||||
}
|
||||
|
||||
const { protocol } = new URL(url);
|
||||
const { protocol, hostname } = new URL(url);
|
||||
|
||||
// Only adjust CORS for assets responses; leave remote http(s) headers intact
|
||||
// Adjust CORS for assets responses and allow blob redirects on affine domains
|
||||
if (protocol === 'assets:') {
|
||||
delete responseHeaders['access-control-allow-origin'];
|
||||
delete responseHeaders['access-control-allow-headers'];
|
||||
@@ -221,6 +238,11 @@ export function registerProtocol() {
|
||||
delete responseHeaders['Access-Control-Allow-Headers'];
|
||||
setHeader(responseHeaders, 'X-Frame-Options', 'SAMEORIGIN');
|
||||
ensureFrameAncestors(responseHeaders, "'self'");
|
||||
} else if (
|
||||
(protocol === 'http:' || protocol === 'https:') &&
|
||||
affineDomains.some(regex => regex.test(hostname))
|
||||
) {
|
||||
allowCors(responseHeaders);
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
||||
Reference in New Issue
Block a user