mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-06 16:20:08 +00:00
feat: portfolio download
This commit is contained in:
parent
e9e6eda7e0
commit
e247d4b51b
2 changed files with 31 additions and 5 deletions
|
|
@ -38,6 +38,18 @@ export const apiResetCandidatePassword = async (id: number): Promise<CreateCandi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const apiGetCandidatePortfolio = async (id: number): Promise<Blob> => {
|
||||||
|
try {
|
||||||
|
const res = await fetch(API_URL + '/admin/candidate/' + id + '/portfolio', {
|
||||||
|
method: 'GET',
|
||||||
|
credentials: 'include',
|
||||||
|
});
|
||||||
|
return await res.blob();
|
||||||
|
} catch (e: any) {
|
||||||
|
throw errorHandler(e, 'Candidate portfolio failed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SSR compatible
|
// SSR compatible
|
||||||
// Logout as admin /admin/logout
|
// Logout as admin /admin/logout
|
||||||
export const apiLogout = async (fetchSsr?: Fetch) => {
|
export const apiLogout = async (fetchSsr?: Fetch) => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { apiResetCandidatePassword } from "$lib/@api/admin";
|
import { apiGetCandidatePortfolio, apiResetCandidatePassword } from "$lib/@api/admin";
|
||||||
import type { CandidateData } from "$lib/stores/candidate";
|
import type { CandidateData } from "$lib/stores/candidate";
|
||||||
import ListElement from "./ListElement.svelte";
|
import ListElement from "./ListElement.svelte";
|
||||||
|
|
||||||
|
|
@ -16,7 +16,17 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadPortfolio() {
|
async function downloadPortfolio() {
|
||||||
|
try {
|
||||||
|
const portfolioBlob = await apiGetCandidatePortfolio(id);
|
||||||
|
const url = window.URL.createObjectURL(new Blob([portfolioBlob]));
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.setAttribute('download', 'PORTFOLIO' + '_' + id + '.zip');
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -40,12 +50,16 @@
|
||||||
</li>
|
</li>
|
||||||
</div>
|
</div>
|
||||||
<div class="ml-20">
|
<div class="ml-20">
|
||||||
<div class="bg-sspsBlue hover:bg-sspsBlueDark transition duration-300 rounded-lg px-10 py-4">
|
<div class="flex flex-col">
|
||||||
<button on:click={e => resetCandidatePassword()} class="text-2xl text-white font-bold">Resetovat heslo</button>
|
<button on:click={e => resetCandidatePassword()} class="">Resetovat heslo</button>
|
||||||
<button on:click={e => resetCandidatePassword()} class="text-2xl text-white font-bold">Resetovat heslo</button>
|
<button on:click={e => downloadPortfolio()} class="mt-40">Stáhnout portfolio</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
button {
|
||||||
|
@apply bg-sspsBlue hover:bg-sspsBlueDark transition duration-300 rounded-lg;
|
||||||
|
@apply text-2xl text-white font-bold px-10 py-4;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue