fix: implement allEntriesByFolder for proxy backend (#262)
This commit is contained in:
parent
3c4973f321
commit
7ca3777197
@ -80,7 +80,9 @@ module.exports = {
|
|||||||
version: 'detect',
|
version: 'detect',
|
||||||
},
|
},
|
||||||
'import/resolver': {
|
'import/resolver': {
|
||||||
typescript: {}, // this loads <rootdir>/tsconfig.json to eslint
|
typescript: {
|
||||||
|
project: 'packages/core/tsconfig.json',
|
||||||
|
}, // this loads <rootdir>/tsconfig.json to eslint
|
||||||
},
|
},
|
||||||
'import/core-modules': ['src'],
|
'import/core-modules': ['src'],
|
||||||
},
|
},
|
||||||
|
@ -10,6 +10,7 @@ import type {
|
|||||||
ImplementationFile,
|
ImplementationFile,
|
||||||
PersistOptions,
|
PersistOptions,
|
||||||
User,
|
User,
|
||||||
|
ImplementationMediaFile,
|
||||||
} from '@staticcms/core/interface';
|
} from '@staticcms/core/interface';
|
||||||
import type { Cursor } from '@staticcms/core/lib/util';
|
import type { Cursor } from '@staticcms/core/lib/util';
|
||||||
import type AssetProxy from '@staticcms/core/valueObjects/AssetProxy';
|
import type AssetProxy from '@staticcms/core/valueObjects/AssetProxy';
|
||||||
@ -89,7 +90,7 @@ export default class ProxyBackend implements BackendClass {
|
|||||||
return Promise.resolve('');
|
return Promise.resolve('');
|
||||||
}
|
}
|
||||||
|
|
||||||
async request(payload: { action: string; params: Record<string, unknown> }) {
|
async request<T>(payload: { action: string; params: Record<string, unknown> }): Promise<T> {
|
||||||
const response = await unsentRequest.fetchWithTimeout(this.proxyUrl, {
|
const response = await unsentRequest.fetchWithTimeout(this.proxyUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
||||||
@ -105,28 +106,32 @@ export default class ProxyBackend implements BackendClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entriesByFolder(folder: string, extension: string, depth: number) {
|
entriesByFolder(
|
||||||
|
folder: string,
|
||||||
|
extension: string,
|
||||||
|
depth: number,
|
||||||
|
): Promise<ImplementationEntry[]> {
|
||||||
return this.request({
|
return this.request({
|
||||||
action: 'entriesByFolder',
|
action: 'entriesByFolder',
|
||||||
params: { branch: this.branch, folder, extension, depth },
|
params: { branch: this.branch, folder, extension, depth },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
entriesByFiles(files: ImplementationFile[]) {
|
entriesByFiles(files: ImplementationFile[]): Promise<ImplementationEntry[]> {
|
||||||
return this.request({
|
return this.request({
|
||||||
action: 'entriesByFiles',
|
action: 'entriesByFiles',
|
||||||
params: { branch: this.branch, files },
|
params: { branch: this.branch, files },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getEntry(path: string) {
|
getEntry(path: string): Promise<ImplementationEntry> {
|
||||||
return this.request({
|
return this.request({
|
||||||
action: 'getEntry',
|
action: 'getEntry',
|
||||||
params: { branch: this.branch, path },
|
params: { branch: this.branch, path },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async persistEntry(entry: BackendEntry, options: PersistOptions) {
|
async persistEntry(entry: BackendEntry, options: PersistOptions): Promise<void> {
|
||||||
const assets = await Promise.all(entry.assets.map(serializeAsset));
|
const assets = await Promise.all(entry.assets.map(serializeAsset));
|
||||||
return this.request({
|
return this.request({
|
||||||
action: 'persistEntry',
|
action: 'persistEntry',
|
||||||
@ -153,8 +158,8 @@ export default class ProxyBackend implements BackendClass {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMediaFile(path: string) {
|
async getMediaFile(path: string): Promise<ImplementationMediaFile> {
|
||||||
const file = await this.request({
|
const file = await this.request<MediaFile>({
|
||||||
action: 'getMediaFile',
|
action: 'getMediaFile',
|
||||||
params: { branch: this.branch, path },
|
params: { branch: this.branch, path },
|
||||||
});
|
});
|
||||||
@ -187,10 +192,10 @@ export default class ProxyBackend implements BackendClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
allEntriesByFolder(
|
allEntriesByFolder(
|
||||||
_folder: string,
|
folder: string,
|
||||||
_extension: string,
|
extension: string,
|
||||||
_depth: number,
|
depth: number,
|
||||||
): Promise<ImplementationEntry[]> {
|
): Promise<ImplementationEntry[]> {
|
||||||
throw new Error('Not supported');
|
return this.entriesByFolder(folder, extension, depth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user