Skip to content

Commit

Permalink
fix: bad keys (#7)
Browse files Browse the repository at this point in the history
* fix: escape keys

* fix: attachment upload key
  • Loading branch information
thezzisu authored Jan 6, 2024
1 parent 6c24df3 commit b1be683
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .yarn/versions/96fd40a9.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declined:
- "@aoi-js/frontend"
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const props = defineProps<{
}>()
async function downloadFile(key: string) {
key = encodeURIComponent(key)
const resp = await http.get(
`contest/${props.contestId}/problem/${props.problem._id}/attachment/${key}/url/download`
)
Expand Down
4 changes: 3 additions & 1 deletion apps/frontend/src/components/contest/RanklistExportBtn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ async function getProfile(_id: string) {
async function exportRanklist() {
toast.info(t('start-generating'))
try {
const endpoint = `contest/${props.contestId}/ranklist/${props.ranklistKey}/url/download`
const endpoint =
`contest/${props.contestId}/` +
`ranklist/${encodeURIComponent(props.ranklistKey)}/url/download`
const { url } = await http.get(endpoint).json<{ url: string }>()
const jsondata = await ky.get(url).json<Ranklist>()
const workbook = xlsx.utils.book_new()
Expand Down
6 changes: 4 additions & 2 deletions apps/frontend/src/components/contest/RanklistSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<VCardSubtitle>
{{ t('term.schedule') }}
</VCardSubtitle>
<SettingsEditor :endpoint="`contest/${contestId}/ranklist/${props.ranklistKey}/settings`">
<SettingsEditor
:endpoint="`contest/${contestId}/ranklist/${encodeURIComponent(props.ranklistKey)}/settings`"
>
<template v-slot="scoped">
<RanklistSettingsInput v-model="scoped.value" />
</template>
Expand Down Expand Up @@ -56,7 +58,7 @@ const emit = defineEmits<{
}>()
async function deleteRanklist() {
await http.delete(`contest/${props.contestId}/ranklist/${props.ranklistKey}`)
await http.delete(`contest/${props.contestId}/ranklist/${encodeURIComponent(props.ranklistKey)}`)
router.push(`/org/${props.orgId}/contest/${props.contestId}/ranklist`)
emit('updated')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ const attachments = useAsyncState(async () => {
const canManage = computed(() => hasCapability(props.contest.capability, 1))
async function downloadFile(key: string) {
key = encodeURIComponent(key)
const resp = await http.get(`contest/${props.contestId}/attachment/${key}/url/download`)
const { url } = await resp.json<{ url: string }>()
window.open(url)
}
async function deleteFile(key: string) {
try {
key = encodeURIComponent(key)
const resp = await http.get(`contest/${props.contestId}/attachment/${key}/url/delete`)
const { url } = await resp.json<{ url: string }>()
await fetch(url, { method: 'DELETE' })
Expand Down Expand Up @@ -122,9 +124,8 @@ watch(
async function uploadFile() {
try {
const resp = await http.get(
`contest/${props.contestId}/attachment/${uploadInfo.key}/url/upload`
)
const key = encodeURIComponent(uploadInfo.key)
const resp = await http.get(`contest/${props.contestId}/attachment/${key}/url/upload`)
const { url } = await resp.json<{ url: string }>()
await fetch(url, {
method: 'PUT',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const { t } = useI18n()
const currentTab = ref()
const admin = useContestCapability('admin')
const endpoint = `contest/${props.contestId}/ranklist/${props.ranklistKey}/url`
const endpoint = `contest/${props.contestId}/ranklist/${encodeURIComponent(props.ranklistKey)}/url`
</script>
<i18n>
en:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ const snackbarText = ref('')
const canManage = computed(() => hasCapability(props.problem.capability, 1))
async function downloadFile(key: string) {
key = encodeURIComponent(key)
const resp = await http.get(`problem/${props.problem._id}/attachment/${key}/url/download`)
const { url } = await resp.json<{ url: string }>()
window.open(url)
}
async function deleteFile(key: string) {
try {
key = encodeURIComponent(key)
const resp = await http.get(`problem/${props.problem._id}/attachment/${key}/url/delete`)
const { url } = await resp.json<{ url: string }>()
await fetch(url, { method: 'DELETE' })
Expand All @@ -121,9 +123,8 @@ const uploadInfo = reactive({
async function uploadFile() {
try {
const resp = await http.get(
`problem/${props.problem._id}/attachment/${uploadInfo.key}/url/upload`
)
const key = encodeURIComponent(uploadInfo.key)
const resp = await http.get(`problem/${props.problem._id}/attachment/${key}/url/upload`)
const { url } = await resp.json<{ url: string }>()
await fetch(url, {
method: 'PUT',
Expand Down

0 comments on commit b1be683

Please sign in to comment.