Skip to content

Commit

Permalink
Use base URL of GitLab for the /uploads URLs (#1482)
Browse files Browse the repository at this point in the history
* Use base URL of GitLab for the `/uploads` URLs

* Update gitlab.js

* Fix non-native uploads

* fixup! Fix non-native uploads

* fixup! Fix non-native uploads

* Update gitlab.yml

* Update gitlab.yml
  • Loading branch information
0x2b3bfa0 authored Oct 24, 2024
1 parent 95e931d commit 4cac5a4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bin/cml/asset/publish.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('CML e2e', () => {
'assets/test.svg'
);

expect(output.startsWith('https://')).toBe(true);
expect(output.startsWith('/uploads/')).toBe(true);
});

test('cml publish /nonexistent produces file error', async () => {
Expand Down
16 changes: 8 additions & 8 deletions src/cml.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ describe('Gitlab tests', () => {
native: true
});

expect(output.startsWith('https://')).toBe(true);
expect(output.includes('cml=png')).toBe(true);
expect(output.startsWith('/uploads/')).toBe(true);
expect(output.includes('cml=png')).toBe(false);
});

test('Publish image using gl with markdown', async () => {
Expand All @@ -159,9 +159,9 @@ describe('Gitlab tests', () => {
native: true
});

expect(output.startsWith('![](https://')).toBe(true);
expect(output.startsWith('![](/uploads/')).toBe(true);
expect(output.endsWith(` "${title}")`)).toBe(true);
expect(output.includes('cml=png')).toBe(true);
expect(output.includes('cml=png')).toBe(false);
});

test('Publish a non image file using gl in markdown', async () => {
Expand All @@ -175,9 +175,9 @@ describe('Gitlab tests', () => {
native: true
});

expect(output.startsWith(`[${title}](https://`)).toBe(true);
expect(output.startsWith(`[${title}](/uploads/`)).toBe(true);
expect(output.endsWith(')')).toBe(true);
expect(output.includes('cml=pdf')).toBe(true);
expect(output.includes('cml=pdf')).toBe(false);
});

test('Publish a non image file using native', async () => {
Expand All @@ -191,9 +191,9 @@ describe('Gitlab tests', () => {
native: true
});

expect(output.startsWith(`[${title}](https://`)).toBe(true);
expect(output.startsWith(`[${title}](/uploads/`)).toBe(true);
expect(output.endsWith(')')).toBe(true);
expect(output.includes('cml=pdf')).toBe(true);
expect(output.includes('cml=pdf')).toBe(false);
});

test('Publish should fail with an invalid driver', async () => {
Expand Down
6 changes: 4 additions & 2 deletions src/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,14 @@ class CML {
({ mime, uri } = await upload(opts));
}

if (!rmWatermark) {
if (!rmWatermark && !native) {
const [, type] = mime.split('/');
uri = watermarkUri({ uri, type });
}

uri = preventcacheUri({ uri });
if (!native) {
uri = preventcacheUri({ uri });
}

if (md && mime.match('(image|video)/.*'))
return `![](${uri}${title ? ` "${title}"` : ''})`;
Expand Down
4 changes: 1 addition & 3 deletions src/drivers/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ class Gitlab {
}

async upload(opts = {}) {
const { repo } = this;

const projectPath = await this.projectPath();
const endpoint = `/projects/${projectPath}/uploads`;
const { size, mime, data } = await fetchUploadData(opts);
Expand All @@ -141,7 +139,7 @@ class Gitlab {

const { url } = await this.request({ endpoint, method: 'POST', body });

return { uri: `${repo}${url}`, mime, size };
return { uri: url, mime, size };
}

async runnerToken(body) {
Expand Down

0 comments on commit 4cac5a4

Please sign in to comment.