fix(git-gateway-gitlab): fix large media support for editorial workflow (#3105)
This commit is contained in:
parent
07fa5b316c
commit
038803c9f2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,28 @@
|
|||||||
|
import fixture from './common/media_library';
|
||||||
|
import { entry1 } from './common/entries';
|
||||||
|
import * as specUtils from './common/spec_utils';
|
||||||
|
|
||||||
|
const backend = 'git-gateway';
|
||||||
|
const provider = 'gitlab';
|
||||||
|
|
||||||
|
describe('Git Gateway (GitLab) Backend Media Library - Large Media', () => {
|
||||||
|
let taskResult = { data: {} };
|
||||||
|
|
||||||
|
before(() => {
|
||||||
|
specUtils.before(taskResult, { publish_mode: 'editorial_workflow', provider }, backend);
|
||||||
|
});
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
specUtils.after(taskResult, backend);
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
specUtils.beforeEach(taskResult, backend);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
specUtils.afterEach(taskResult, backend);
|
||||||
|
});
|
||||||
|
|
||||||
|
fixture({ entries: [entry1], getUser: () => taskResult.data.user });
|
||||||
|
});
|
@ -60,6 +60,7 @@ async function prepareTestGitLabRepo() {
|
|||||||
console.log('Creating repository', testRepoName);
|
console.log('Creating repository', testRepoName);
|
||||||
await client.Projects.create({
|
await client.Projects.create({
|
||||||
name: testRepoName,
|
name: testRepoName,
|
||||||
|
lfs_enabled: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const tempDir = path.join('.temp', testRepoName);
|
const tempDir = path.join('.temp', testRepoName);
|
||||||
|
@ -279,7 +279,10 @@ export default class GitGateway implements Implementation {
|
|||||||
files.map(async file => {
|
files.map(async file => {
|
||||||
if (client.matchPath(file.path)) {
|
if (client.matchPath(file.path)) {
|
||||||
const { id, path } = file;
|
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]);
|
const url = await client.getDownloadURL(largeMediaDisplayURLs[id]);
|
||||||
return {
|
return {
|
||||||
id,
|
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 client = await this.getLargeMediaClient();
|
||||||
const filesPromise = entriesByFiles(
|
const readFile = (
|
||||||
mediaFiles,
|
path: string,
|
||||||
this.api!.readFile.bind(this.api!),
|
id: string | null | undefined,
|
||||||
'Git-Gateway',
|
{ parseText }: { parseText: boolean },
|
||||||
);
|
) => this.api!.readFile(path, id, { branch, parseText });
|
||||||
|
|
||||||
|
const filesPromise = entriesByFiles(mediaFiles, readFile, 'Git-Gateway');
|
||||||
|
|
||||||
return filesPromise
|
return filesPromise
|
||||||
.then(items =>
|
.then(items =>
|
||||||
|
@ -453,6 +453,18 @@ export default class API {
|
|||||||
return branches;
|
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) {
|
async isFileExists(path: string, branch: string) {
|
||||||
const fileExists = await this.requestText({
|
const fileExists = await this.requestText({
|
||||||
method: 'HEAD',
|
method: 'HEAD',
|
||||||
@ -498,9 +510,14 @@ export default class API {
|
|||||||
const mergeRequest = await this.getBranchMergeRequest(branch);
|
const mergeRequest = await this.getBranchMergeRequest(branch);
|
||||||
const diff = await this.getDifferences(mergeRequest.sha);
|
const diff = await this.getDifferences(mergeRequest.sha);
|
||||||
const path = diff.find(d => d.old_path.includes(slug))?.old_path as string;
|
const path = diff.find(d => d.old_path.includes(slug))?.old_path as string;
|
||||||
// TODO: get real file id
|
|
||||||
const mediaFiles = await Promise.all(
|
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 label = mergeRequest.labels.find(isCMSLabel) as string;
|
||||||
const status = labelToStatus(label);
|
const status = labelToStatus(label);
|
||||||
|
@ -308,9 +308,6 @@ export default class GitLab implements Implementation {
|
|||||||
const data = await this.api!.readUnpublishedBranchFile(contentKey);
|
const data = await this.api!.readUnpublishedBranchFile(contentKey);
|
||||||
const mediaFiles = await loadEntryMediaFiles(
|
const mediaFiles = await loadEntryMediaFiles(
|
||||||
data.metaData.branch,
|
data.metaData.branch,
|
||||||
// TODO: fix this
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
||||||
// @ts-ignore
|
|
||||||
data.metaData.objects.entry.mediaFiles,
|
data.metaData.objects.entry.mediaFiles,
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user