fix(git-gateway-gitlab): fix large media support for editorial workflow (#3105)
This commit is contained in:
@ -279,7 +279,10 @@ export default class GitGateway implements Implementation {
|
||||
files.map(async file => {
|
||||
if (client.matchPath(file.path)) {
|
||||
const { id, path } = file;
|
||||
const largeMediaDisplayURLs = await this.getLargeMediaDisplayURLs([{ ...file, id }]);
|
||||
const largeMediaDisplayURLs = await this.getLargeMediaDisplayURLs(
|
||||
[{ ...file, id }],
|
||||
branch,
|
||||
);
|
||||
const url = await client.getDownloadURL(largeMediaDisplayURLs[id]);
|
||||
return {
|
||||
id,
|
||||
@ -379,13 +382,18 @@ export default class GitGateway implements Implementation {
|
||||
},
|
||||
);
|
||||
}
|
||||
async getLargeMediaDisplayURLs(mediaFiles: { path: string; id: string | null }[]) {
|
||||
async getLargeMediaDisplayURLs(
|
||||
mediaFiles: { path: string; id: string | null }[],
|
||||
branch = this.branch,
|
||||
) {
|
||||
const client = await this.getLargeMediaClient();
|
||||
const filesPromise = entriesByFiles(
|
||||
mediaFiles,
|
||||
this.api!.readFile.bind(this.api!),
|
||||
'Git-Gateway',
|
||||
);
|
||||
const readFile = (
|
||||
path: string,
|
||||
id: string | null | undefined,
|
||||
{ parseText }: { parseText: boolean },
|
||||
) => this.api!.readFile(path, id, { branch, parseText });
|
||||
|
||||
const filesPromise = entriesByFiles(mediaFiles, readFile, 'Git-Gateway');
|
||||
|
||||
return filesPromise
|
||||
.then(items =>
|
||||
|
@ -453,6 +453,18 @@ export default class API {
|
||||
return branches;
|
||||
}
|
||||
|
||||
async getFileId(path: string, branch: string) {
|
||||
const request = await this.request({
|
||||
method: 'HEAD',
|
||||
url: `${this.repoURL}/repository/files/${encodeURIComponent(path)}`,
|
||||
params: { ref: branch },
|
||||
cache: 'no-store',
|
||||
});
|
||||
|
||||
const blobId = request.headers.get('X-Gitlab-Blob-Id') as string;
|
||||
return blobId;
|
||||
}
|
||||
|
||||
async isFileExists(path: string, branch: string) {
|
||||
const fileExists = await this.requestText({
|
||||
method: 'HEAD',
|
||||
@ -498,9 +510,14 @@ export default class API {
|
||||
const mergeRequest = await this.getBranchMergeRequest(branch);
|
||||
const diff = await this.getDifferences(mergeRequest.sha);
|
||||
const path = diff.find(d => d.old_path.includes(slug))?.old_path as string;
|
||||
// TODO: get real file id
|
||||
const mediaFiles = await Promise.all(
|
||||
diff.filter(d => d.old_path !== path).map(d => ({ path: d.new_path, id: null })),
|
||||
diff
|
||||
.filter(d => d.old_path !== path)
|
||||
.map(async d => {
|
||||
const path = d.new_path;
|
||||
const id = await this.getFileId(path, branch);
|
||||
return { path, id };
|
||||
}),
|
||||
);
|
||||
const label = mergeRequest.labels.find(isCMSLabel) as string;
|
||||
const status = labelToStatus(label);
|
||||
|
@ -308,9 +308,6 @@ export default class GitLab implements Implementation {
|
||||
const data = await this.api!.readUnpublishedBranchFile(contentKey);
|
||||
const mediaFiles = await loadEntryMediaFiles(
|
||||
data.metaData.branch,
|
||||
// TODO: fix this
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
||||
// @ts-ignore
|
||||
data.metaData.objects.entry.mediaFiles,
|
||||
);
|
||||
return {
|
||||
|
Reference in New Issue
Block a user