一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
48 行
1.2 KiB
TypeScript
48 行
1.2 KiB
TypeScript
import BaseModel from '../BaseModel';
|
|
import Note from '../models/Note';
|
|
import Resource from '../models/Resource';
|
|
import ResourceLocalState from '../models/ResourceLocalState';
|
|
import { ResourceEntity } from '../services/database/types';
|
|
|
|
let resourceCache_: AttachedResources = {};
|
|
|
|
export function clearResourceCache() {
|
|
resourceCache_ = {};
|
|
}
|
|
|
|
interface AttachedResource {
|
|
item: ResourceEntity;
|
|
localState: ResourceLocalState;
|
|
}
|
|
export interface AttachedResources {
|
|
[id: string]: AttachedResource;
|
|
}
|
|
|
|
export default async function attachedResources(noteBody: string): Promise<AttachedResources> {
|
|
if (!noteBody) return {};
|
|
const resourceIds = await Note.linkedItemIdsByType(BaseModel.TYPE_RESOURCE, noteBody);
|
|
|
|
const output: AttachedResources = {};
|
|
for (let i = 0; i < resourceIds.length; i++) {
|
|
const id = resourceIds[i];
|
|
|
|
if (resourceCache_[id]) {
|
|
output[id] = resourceCache_[id];
|
|
} else {
|
|
const resource = await Resource.load(id);
|
|
const localState = await Resource.localState(resource);
|
|
|
|
const o = {
|
|
item: resource,
|
|
localState: localState,
|
|
};
|
|
|
|
// eslint-disable-next-line require-atomic-updates
|
|
resourceCache_[id] = o;
|
|
output[id] = o;
|
|
}
|
|
}
|
|
|
|
return output;
|
|
}
|