Skip to content

Commit

Permalink
Resolve alias links
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Aug 4, 2022
1 parent 22f6ca1 commit 171f09e
Showing 1 changed file with 62 additions and 10 deletions.
72 changes: 62 additions & 10 deletions packages/web-runtime/src/pages/resolvePublicLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
<div class="oc-height-1-1 oc-link-resolve">
<h1 class="oc-invisible-sr">{{ pageTitle }}</h1>
<div class="oc-card oc-border oc-rounded oc-position-center oc-text-center oc-width-large">
<template v-if="isPasswordRequiredTask.isRunning || !isPasswordRequiredTask.last">
<template
v-if="
loadTokenInfoTask.isRunning ||
!loadTokenInfoTask.last ||
isPasswordRequiredTask.isRunning ||
!isPasswordRequiredTask.last
"
>
<div class="oc-card-header">
<h2 key="public-link-loading">
<translate>Loading public link…</translate>
Expand All @@ -12,17 +19,17 @@
<oc-spinner :aria-hidden="true" />
</div>
</template>
<template v-else-if="isPasswordRequiredTask.isError">
<template v-else-if="loadTokenInfoTask.isError || isPasswordRequiredTask.isError">
<div class="oc-card-header oc-link-resolve-error-title">
<h2 key="public-link-error">
<translate>An error occurred while loading the public link</translate>
</h2>
</div>
<div class="oc-card-body oc-link-resolve-error-message">
<p class="oc-text-lead">{{ isPasswordRequiredTask.last.error }}</p>
<p class="oc-text-lead">{{ loadTokenInfoTask.last.error }}</p>
</div>
</template>
<template v-else-if="isPasswordRequiredTask.last.value">
<template v-else-if="isPasswordRequiredTask.last && isPasswordRequiredTask.last.value">
<form @submit.prevent="resolvePublicLink(true)">
<div class="oc-card-header">
<h2>
Expand Down Expand Up @@ -68,7 +75,8 @@ import {
queryItemAsString,
useClientService,
useRouteParam,
useRouteQuery
useRouteQuery,
useStore
} from 'web-pkg/src/composables'
import { useTask } from 'vue-concurrency'
import { ref, unref, computed, defineComponent } from "@vue/composition-api";
Expand All @@ -77,9 +85,18 @@ export default defineComponent({
name: 'ResolvePublicLink',
setup() {
const { owncloudSdk } = useClientService()
const store = useStore()
const token = useRouteParam('token')
const password = ref('')
const tokenInfo = ref({})
const isLoggedInUser = computed(() => {
return !!store.getters.user?.id
})
const isPasswordRequiredTask = useTask(function* (signal) {
if (unref(tokenInfo)) {
return unref(tokenInfo).password_protected === 'true'
}
try {
yield owncloudSdk.publicFiles.list(unref(token), '', DavProperties.PublicLink, '0')
return false
Expand All @@ -90,6 +107,18 @@ export default defineComponent({
throw error
}
})
const loadTokenInfoTask = useTask(function* (signal, ref) {
let tokenInfo
try {
if (unref(isLoggedInUser)) {
tokenInfo = yield owncloudSdk.shares.getProtectedTokenInfo(unref(token))
} else {
tokenInfo = yield owncloudSdk.shares.getUnprotectedTokenInfo(unref(token))
}
} catch (e) { } // oC10
ref.tokenInfo = tokenInfo
})
const loadPublicLinkTask = useTask(function* (signal) {
const files = yield owncloudSdk.publicFiles.list(
unref(token),
Expand All @@ -109,13 +138,16 @@ export default defineComponent({
redirectUrl: useRouteQuery('redirectUrl'),
token,
password,
loadTokenInfoTask,
isPasswordRequiredTask,
loadPublicLinkTask,
wrongPassword
wrongPassword,
isLoggedInUser,
tokenInfo
}
},
computed: {
...mapGetters(['configuration']),
...mapGetters(['configuration', 'user']),
pageTitle() {
return this.$gettext(this.$route.meta.title)
Expand All @@ -133,14 +165,34 @@ export default defineComponent({
}
},
async mounted() {
const passwordRequired = await this.isPasswordRequiredTask.perform()
if (!passwordRequired) {
await this.loadTokenInfoTask.perform(this)
const passwordProtected = await this.isPasswordRequiredTask.perform()
if (!passwordProtected) {
await this.resolvePublicLink(false)
}
},
methods: {
async resolvePublicLink(passwordRequired) {
const publicLink = await this.loadPublicLinkTask.perform()
let publicLink
// @TODO handle password
if (this.tokenInfo && !passwordRequired) {
const fullPath = this.tokenInfo.storage_id + '$' + this.tokenInfo.space_id + '!' + this.tokenInfo.opaque_id
try {
publicLink = await this.loadPublicLinkTask.perform()
} catch (e) {
// alias link
if (!this.isLoggedInUser) {
// @TODO add redirect to the actual route
return this.$router.push({ name: '/login' })
}
return this.$router.push({ name: 'files-spaces-personal', params: { storageId: fullPath } })
}
} else {
publicLink = await this.loadPublicLinkTask.perform()
}
if (this.loadPublicLinkTask.isError) {
return
}
Expand Down

0 comments on commit 171f09e

Please sign in to comment.