Skip to content

Commit

Permalink
fix: send url to bitly to have cool curl command
Browse files Browse the repository at this point in the history
fixes #154
  • Loading branch information
edewit committed Oct 22, 2019
1 parent b21f6b5 commit 98ceb66
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Let user Generate default application 1`] = `"/api/download?g=org.acme&a=code-with-quarkus&v=1.0.0-SNAPSHOT&c=org.acme.ExampleResource&"`;
exports[`Let user Generate default application 1`] = `"http://bit.ly/2Mzdn9Z"`;

exports[`Let user customize an Application and Generate it 1`] = `"/api/download?g=io.test.group&a=custom-test-app&v=1.0.0-TEST&c=io.test.pack.ExampleResource&e=io.quarkus%3Aquarkus-arc&e=io.quarkus%3Aquarkus-resteasy&e=io.quarkus%3Aquarkus-resteasy-jackson"`;
exports[`Let user customize an Application and Generate it 1`] = `"http://bit.ly/2Mzdn9Z"`;
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ jest.mock('../backend-api', () => ({
"order": 6
},
]),
fetchConfig: () => { throw new Error("not used"); }
fetchConfig: () => { throw new Error("not used"); },
shortenUrl: async (url: string) => Promise.resolve(
{
link: 'http://bit.ly/2Mzdn9Z'
})
}));


Expand Down
18 changes: 17 additions & 1 deletion src/main/frontend/src/code-quarkus/backend-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,20 @@ export async function fetchConfig() {
environment: 'dev'
}
}
}
}

export async function shortenUrl(downloadLink: string) {
const response = await fetch('https://api-ssl.bitly.com/v4/shorten', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer a3badec1a128e46e42f36a138165cbbd21ed6cee'
},
body: JSON.stringify({
'group_guid': 'Bjam8omLBjB',
'long_url': downloadLink
})
});
return response.ok ? await response.json() : undefined
}
5 changes: 4 additions & 1 deletion src/main/frontend/src/code-quarkus/code-quarkus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CodeQuarkusForm } from './form';
import { Header } from './header';
import './code-quarkus.scss';
import { NextSteps } from './next-steps';
import { shortenUrl } from './backend-api';

enum Status {
EDITION = 'EDITION', RUNNING = 'RUNNING', COMPLETED = 'COMPLETED', ERROR = 'ERROR', DOWNLOADED = 'DOWNLOADED'
Expand Down Expand Up @@ -45,8 +46,10 @@ async function generateProject(project: QuarkusProject): Promise<{ downloadLink:
}
const backendUrl = process.env.REACT_APP_BACKEND_URL || publicUrl;
const downloadLink = `${backendUrl}/api/download?${stringify(params)}`;

const data = await shortenUrl(downloadLink);
window.open(downloadLink, '_blank');
return { downloadLink };
return { downloadLink: data ? data.link : downloadLink };
}

const DEFAULT_PROJECT = {
Expand Down
2 changes: 2 additions & 0 deletions src/main/frontend/src/code-quarkus/next-steps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function NextSteps(props: NextStepsProps) {
const close = (reset?: boolean) => {
props.onClose && props.onClose(reset);
};
const curlCmd = 'curl --output code-with-quarkus.zip ' + (props.downloadLink as string).replace(/&/g, '\\&');
return (
<Modal
title="Your Quarkus Application is Ready!"
Expand All @@ -32,6 +33,7 @@ export function NextSteps(props: NextStepsProps) {
<TextContent>
<p>Your download should start shortly. If it doesn't, please use the direct link:</p>
<Button component="a" href={props.downloadLink as string} aria-label="Download link" className="download-button">Download the zip</Button>
<code>$ {curlCmd} <CopyToClipboard eventId="Download-via-curl-Command" content={curlCmd} /></code>
<h1>What's next?</h1>
<div>
Unzip the project and start playing with Quarkus by running:
Expand Down

0 comments on commit 98ceb66

Please sign in to comment.