🥅 Catching download-error
This commit is contained in:
@@ -8,6 +8,7 @@ from fastapi import APIRouter, HTTPException
|
|||||||
from fastapi.responses import StreamingResponse
|
from fastapi.responses import StreamingResponse
|
||||||
|
|
||||||
from classquiz.config import settings, storage
|
from classquiz.config import settings, storage
|
||||||
|
from classquiz.storage.errors import DownloadingFailedError
|
||||||
|
|
||||||
settings = settings()
|
settings = settings()
|
||||||
|
|
||||||
@@ -20,8 +21,10 @@ file_regex = r"^[a-z0-9]{8}-[a-z0-9-]{27}--[a-z0-9-]{36}$"
|
|||||||
async def download_file(file_name: str):
|
async def download_file(file_name: str):
|
||||||
if not re.match(file_regex, file_name):
|
if not re.match(file_regex, file_name):
|
||||||
raise HTTPException(status_code=400, detail="Invalid file name")
|
raise HTTPException(status_code=400, detail="Invalid file name")
|
||||||
|
try:
|
||||||
download = await storage.download(file_name)
|
download = await storage.download(file_name)
|
||||||
|
except DownloadingFailedError:
|
||||||
|
raise HTTPException(status_code=404, detail="File not found")
|
||||||
if download is None:
|
if download is None:
|
||||||
raise HTTPException(status_code=404, detail="File not found")
|
raise HTTPException(status_code=404, detail="File not found")
|
||||||
|
|
||||||
|
|||||||
Generated
+3
-3
@@ -89,7 +89,7 @@ devDependencies:
|
|||||||
'@sentry/tracing': 7.20.0
|
'@sentry/tracing': 7.20.0
|
||||||
'@sveltejs/adapter-auto': 1.0.0-next.89
|
'@sveltejs/adapter-auto': 1.0.0-next.89
|
||||||
'@sveltejs/adapter-node': 1.0.0-next.100
|
'@sveltejs/adapter-node': 1.0.0-next.100
|
||||||
'@sveltejs/kit': 1.0.0-next.555_svelte@3.53.1+vite@3.2.4
|
'@sveltejs/kit': 1.0.0-next.560_svelte@3.53.1+vite@3.2.4
|
||||||
'@tailwindcss/typography': 0.5.8_tailwindcss@3.2.4
|
'@tailwindcss/typography': 0.5.8_tailwindcss@3.2.4
|
||||||
'@types/canvas-confetti': 1.6.0
|
'@types/canvas-confetti': 1.6.0
|
||||||
'@types/cookie': 0.5.1
|
'@types/cookie': 0.5.1
|
||||||
@@ -954,10 +954,10 @@ packages:
|
|||||||
rollup: 2.79.1
|
rollup: 2.79.1
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/@sveltejs/kit/1.0.0-next.555_svelte@3.53.1+vite@3.2.4:
|
/@sveltejs/kit/1.0.0-next.560_svelte@3.53.1+vite@3.2.4:
|
||||||
resolution:
|
resolution:
|
||||||
{
|
{
|
||||||
integrity: sha512-hrxmS77sLe3l0G1VTRm2fhM+VgVBiW7fuxluB10dnb3p3e5QnjuMDDPyxYwobzGnNYcXRm/Wu3z7CmGHhHGmag==
|
integrity: sha512-ldZJyd+jfQWVkOkRHq25cXMffhL5MgB1Uzhhw1ngF8ezB38P/g4T+5ohP8wuk2lxPJIjbY3S6BeXN5mod9XOhA==
|
||||||
}
|
}
|
||||||
engines: { node: '>=16.14' }
|
engines: { node: '>=16.14' }
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
<!--
|
||||||
|
- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
-->
|
||||||
|
<script lang="ts">
|
||||||
|
export let text;
|
||||||
|
let internal_text = '';
|
||||||
|
/*
|
||||||
|
const markSelection = (function() {
|
||||||
|
const markerTextChar = '\ufeff';
|
||||||
|
const markerTextCharEntity = '';
|
||||||
|
|
||||||
|
let markerEl, markerId = 'sel_' + new Date().getTime() + '_' + Math.random().toString().substr(2);
|
||||||
|
|
||||||
|
let selectionEl;
|
||||||
|
|
||||||
|
return function(win) {
|
||||||
|
win = win || window;
|
||||||
|
const doc = win.document;
|
||||||
|
let sel, range;
|
||||||
|
// Branch for IE <= 8
|
||||||
|
if (doc.selection && doc.selection.createRange) {
|
||||||
|
// Clone the TextRange and collapse
|
||||||
|
range = doc.selection.createRange().duplicate();
|
||||||
|
range.collapse(false);
|
||||||
|
|
||||||
|
// Create the marker element containing a single invisible character by creating literal HTML and insert it
|
||||||
|
range.pasteHTML('<span id="' + markerId + '" style="position: relative;">' + markerTextCharEntity + '</span>');
|
||||||
|
markerEl = doc.getElementById(markerId);
|
||||||
|
} else if (win.getSelection) {
|
||||||
|
sel = win.getSelection();
|
||||||
|
range = sel.getRangeAt(0).cloneRange();
|
||||||
|
range.collapse(false);
|
||||||
|
|
||||||
|
// Create the marker element containing a single invisible character using DOM methods and insert it
|
||||||
|
markerEl = doc.createElement('span');
|
||||||
|
markerEl.id = markerId;
|
||||||
|
markerEl.appendChild(doc.createTextNode(markerTextChar));
|
||||||
|
range.insertNode(markerEl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (markerEl) {
|
||||||
|
// Lazily create element to be placed next to the selection
|
||||||
|
if (!selectionEl) {
|
||||||
|
selectionEl = doc.createElement('div');
|
||||||
|
selectionEl.style.border = 'solid darkblue 1px';
|
||||||
|
selectionEl.style.backgroundColor = 'lightgoldenrodyellow';
|
||||||
|
selectionEl.innerHTML = '<- selection';
|
||||||
|
selectionEl.style.position = 'absolute';
|
||||||
|
|
||||||
|
doc.body.appendChild(selectionEl);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find markerEl position http://www.quirksmode.org/js/findpos.html
|
||||||
|
var obj = markerEl;
|
||||||
|
var left = 0, top = 0;
|
||||||
|
do {
|
||||||
|
left += obj.offsetLeft;
|
||||||
|
top += obj.offsetTop;
|
||||||
|
} while (obj = obj.offsetParent);
|
||||||
|
|
||||||
|
// Move the button into place.
|
||||||
|
// Substitute your jQuery stuff in here
|
||||||
|
selectionEl.style.left = left + 'px';
|
||||||
|
selectionEl.style.top = top + 'px';
|
||||||
|
|
||||||
|
markerEl.parentNode.removeChild(markerEl);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();*/
|
||||||
|
// $: console.log(document.getSelection().toString())
|
||||||
|
/*
|
||||||
|
const markSelection = () => {
|
||||||
|
const sel = document.getSelection();
|
||||||
|
console.log(sel.toString());
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
const bold_regex = /.*\*\*(.+)\*\*.*/gm; // **bold**
|
||||||
|
const italic_regex = /.*\|\|(.+)\|\|.*/gm; // *italic*
|
||||||
|
const strikethrough_regex = /.*~~(.+)~~.*/gm; // ~~strikethrough~~
|
||||||
|
const sub_regex = /.*__(.+)__.*/gm; // __sub__
|
||||||
|
const sup_regex = /.*--(.+)--.*/gm; // --sup--
|
||||||
|
const process_input = () => {
|
||||||
|
let output = internal_text;
|
||||||
|
output = output.replace(bold_regex, '<b>$1</b>');
|
||||||
|
output = output.replace(italic_regex, '<i>$1</i>');
|
||||||
|
output = output.replace(strikethrough_regex, '<del>$1</del>');
|
||||||
|
output = output.replace(sub_regex, '<sub>$1</sub>');
|
||||||
|
output = output.replace(sup_regex, '<sup>$1</sup>');
|
||||||
|
console.log(output);
|
||||||
|
};
|
||||||
|
|
||||||
|
$: {
|
||||||
|
process_input();
|
||||||
|
internal_text;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<input bind:value={internal_text} />
|
||||||
Reference in New Issue
Block a user