diff --git a/packages/netlify-cms-proxy-server/src/middlewares/joi/index.ts b/packages/netlify-cms-proxy-server/src/middlewares/joi/index.ts index b2cdd4b0..6189a2e0 100644 --- a/packages/netlify-cms-proxy-server/src/middlewares/joi/index.ts +++ b/packages/netlify-cms-proxy-server/src/middlewares/joi/index.ts @@ -57,7 +57,7 @@ export const defaultSchema = ({ path = requiredString } = {}) => { is: 'entriesByFiles', then: defaultParams.keys({ files: Joi.array() - .items(Joi.object({ path })) + .items(Joi.object({ path, label: Joi.string() })) .required(), }), }, diff --git a/packages/netlify-cms-proxy-server/src/middlewares/localFs/index.ts b/packages/netlify-cms-proxy-server/src/middlewares/localFs/index.ts index f52e6514..8b87e8be 100644 --- a/packages/netlify-cms-proxy-server/src/middlewares/localFs/index.ts +++ b/packages/netlify-cms-proxy-server/src/middlewares/localFs/index.ts @@ -38,23 +38,23 @@ export const localFsMiddleware = ({ repoPath }: Options) => { const payload = body.params as EntriesByFolderParams; const { folder, extension, depth } = payload; const entries = await listRepoFiles(repoPath, folder, extension, depth).then(files => - entriesFromFiles(repoPath, files), + entriesFromFiles( + repoPath, + files.map(file => ({ path: file })), + ), ); res.json(entries); break; } case 'entriesByFiles': { const payload = body.params as EntriesByFilesParams; - const entries = await entriesFromFiles( - repoPath, - payload.files.map(file => file.path), - ); + const entries = await entriesFromFiles(repoPath, payload.files); res.json(entries); break; } case 'getEntry': { const payload = body.params as GetEntryParams; - const [entry] = await entriesFromFiles(repoPath, [payload.path]); + const [entry] = await entriesFromFiles(repoPath, [{ path: payload.path }]); res.json(entry); break; } diff --git a/packages/netlify-cms-proxy-server/src/middlewares/localGit/index.ts b/packages/netlify-cms-proxy-server/src/middlewares/localGit/index.ts index ad103105..ee73c155 100644 --- a/packages/netlify-cms-proxy-server/src/middlewares/localGit/index.ts +++ b/packages/netlify-cms-proxy-server/src/middlewares/localGit/index.ts @@ -98,7 +98,7 @@ const entriesFromDiffs = async ( ); const entryPath = data.metaData.objects.entry.path; const [entry] = await runOnBranch(git, cmsBranch, () => - entriesFromFiles(repoPath, [entryPath]), + entriesFromFiles(repoPath, [{ path: entryPath }]), ); const rawDiff = await git.diff([branch, cmsBranch, '--', entryPath]); @@ -218,7 +218,10 @@ export const localGitMiddleware = ({ repoPath }: Options) => { const { folder, extension, depth } = payload; const entries = await runOnBranch(git, branch, () => listRepoFiles(repoPath, folder, extension, depth).then(files => - entriesFromFiles(repoPath, files), + entriesFromFiles( + repoPath, + files.map(file => ({ path: file })), + ), ), ); res.json(entries); @@ -227,10 +230,7 @@ export const localGitMiddleware = ({ repoPath }: Options) => { case 'entriesByFiles': { const payload = body.params as EntriesByFilesParams; const entries = await runOnBranch(git, branch, () => - entriesFromFiles( - repoPath, - payload.files.map(file => file.path), - ), + entriesFromFiles(repoPath, payload.files), ); res.json(entries); break; @@ -238,7 +238,7 @@ export const localGitMiddleware = ({ repoPath }: Options) => { case 'getEntry': { const payload = body.params as GetEntryParams; const [entry] = await runOnBranch(git, branch, () => - entriesFromFiles(repoPath, [payload.path]), + entriesFromFiles(repoPath, [{ path: payload.path }]), ); res.json(entry); break; diff --git a/packages/netlify-cms-proxy-server/src/middlewares/utils/entries.ts b/packages/netlify-cms-proxy-server/src/middlewares/utils/entries.ts index 741b2549..6c066a6e 100644 --- a/packages/netlify-cms-proxy-server/src/middlewares/utils/entries.ts +++ b/packages/netlify-cms-proxy-server/src/middlewares/utils/entries.ts @@ -12,17 +12,23 @@ const sha256 = (buffer: Buffer) => { // normalize windows os path format const normalizePath = (path: string) => path.replace(/\\/g, '/'); -export const entriesFromFiles = async (repoPath: string, files: string[]) => { +export const entriesFromFiles = async ( + repoPath: string, + files: { path: string; label?: string }[], +) => { return Promise.all( files.map(async file => { try { - const content = await fs.readFile(path.join(repoPath, file)); + const content = await fs.readFile(path.join(repoPath, file.path)); return { data: content.toString(), - file: { path: normalizePath(file), id: sha256(content) }, + file: { path: normalizePath(file.path), id: sha256(content) }, }; } catch (e) { - return { data: null, file: { path: file, id: null } }; + return { + data: null, + file: { path: normalizePath(file.path), label: file.label, id: null }, + }; } }), );