Skip to content

Commit

Permalink
example: fix Vue3 example
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed May 31, 2022
1 parent 861f264 commit 77b351a
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 871 deletions.
20 changes: 10 additions & 10 deletions examples/vue3/index.html
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
15 changes: 9 additions & 6 deletions examples/vue3/package.json
Expand Up @@ -4,17 +4,20 @@
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build"
"build": "vite build",
"preview": "vite preview --port 5050"
},
"dependencies": {
"@uppy/core": "workspace:*",
"@uppy/dashboard": "workspace:*",
"@uppy/drag-drop": "workspace:*",
"@uppy/progress-bar": "workspace:*",
"@uppy/transloadit": "workspace:*",
"@uppy/vue": "workspace:*",
"core-js": "^3.6.5",
"shallow-equal": "^1.2.1",
"vue": "^3.0.4"
"vue": "^3.2.33"
},
"devDependencies": {
"@vue/compiler-sfc": "^3.0.4",
"vite": "^1.0.0-rc.13"
"@vitejs/plugin-vue": "^2.3.1",
"vite": "^2.7.1"
}
}
66 changes: 46 additions & 20 deletions examples/vue3/src/App.vue
@@ -1,3 +1,7 @@
<script setup>
import { Dashboard, DashboardModal, DragDrop, ProgressBar } from '@uppy/vue'
</script>

<template>
<div id="app">
<!-- <HelloWorld msg="Welcome to Uppy Vue Demo"/> -->
Expand All @@ -13,7 +17,7 @@
/>
Show Dashboard
</label>
<dashboard
<Dashboard
v-if="showInlineDashboard"
:uppy="uppy"
:props="{
Expand All @@ -23,7 +27,7 @@
<h2>Modal Dashboard</h2>
<div>
<button @click="open = true">Show Dashboard</button>
<dashboard-modal
<DashboardModal
:uppy="uppy2"
:open="open"
:props="{
Expand All @@ -33,7 +37,7 @@
</div>

<h2>Drag Drop Area</h2>
<drag-drop
<DragDrop
:uppy="uppy"
:props="{
locale: {
Expand All @@ -46,7 +50,7 @@
/>

<h2>Progress Bar</h2>
<progress-bar
<ProgressBar
:uppy="uppy"
:props="{
hideAfterFinish: false
Expand All @@ -57,22 +61,45 @@

<script>
import Uppy from '@uppy/core'
// import Tus from '@uppy/tus'
import { Dashboard, DashboardModal, DragDrop, ProgressBar } from '@uppy/vue'
import Transloadit from '@uppy/transloadit'
import { defineComponent } from 'vue'
export default {
name: 'App',
components: {
Dashboard,
DashboardModal,
DragDrop,
ProgressBar
},
import generateSignatureIfSecret from './generateSignatureIfSecret.js'
const {
VITE_TRANSLOADIT_KEY : TRANSLOADIT_KEY,
// Your Transloadit secret SHALL NOT be accessible in your Vue file, this is
// there for illustration purposes only.
VITE_TRANSLOADIT_SECRET : TRANSLOADIT_SECRET,
VITE_TRANSLOADIT_TEMPLATE : TRANSLOADIT_TEMPLATE,
VITE_TRANSLOADIT_SERVICE_URL : TRANSLOADIT_SERVICE_URL,
} = import.meta.env
async function getAssemblyOptions () {
return generateSignatureIfSecret(TRANSLOADIT_SECRET, {
auth: {
key: TRANSLOADIT_KEY,
},
// It's more secure to use a template_id and enable
// Signature Authentication
template_id: TRANSLOADIT_TEMPLATE,
})
}
export default defineComponent({
computed: {
uppy: () => new Uppy({ id: 'uppy1', autoProceed: true, debug: true }),
// .use(Tus, { endpoint: 'https://tusd.tusdemo.net/files/' }),
uppy: () => new Uppy({ id: 'uppy1', autoProceed: true, debug: true })
.use(Transloadit, {
service: TRANSLOADIT_SERVICE_URL,
waitForEncoding: true,
getAssemblyOptions,
}),
uppy2: () => new Uppy({ id: 'uppy2', autoProceed: false, debug: true })
// .use(Tus, { endpoint: 'https://tusd.tusdemo.net/files/' }),
.use(Transloadit, {
service: TRANSLOADIT_SERVICE_URL,
waitForEncoding: true,
getAssemblyOptions,
}),
},
data () {
return {
Expand All @@ -83,15 +110,14 @@ export default {
methods: {
handleClose() { this.open = false }
},
}
})
</script>

<style src='@uppy/core/dist/style.css'></style>
<style src='@uppy/dashboard/dist/style.css'></style>
<style src='@uppy/drag-drop/dist/style.css'></style>
<style src='@uppy/progress-bar/dist/style.css'></style>


<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
Expand Down
34 changes: 34 additions & 0 deletions examples/vue3/src/generateSignatureIfSecret.js
@@ -0,0 +1,34 @@
const enc = new TextEncoder('utf-8')
async function sign (secret, body) {
const algorithm = { name: 'HMAC', hash: 'SHA-384' }

const key = await crypto.subtle.importKey('raw', enc.encode(secret), algorithm, false, ['sign', 'verify'])
const signature = await crypto.subtle.sign(algorithm.name, key, enc.encode(body))
return `sha384:${Array.from(new Uint8Array(signature), x => x.toString(16).padStart(2, '0')).join('')}`
}
function getExpiration (future) {
return new Date(Date.now() + future)
.toISOString()
.replace('T', ' ')
.replace(/\.\d+Z$/, '+00:00')
}
/**
* Adds an expiration date and signs the params object if a secret is passed to
* it. If no secret is given, it returns the same object.
*
* @param {string | undefined} secret
* @param {object} params
* @returns {{ params: string, signature?: string }}
*/
export default async function generateSignatureIfSecret (secret, params) {
let signature
if (secret) {
// eslint-disable-next-line no-param-reassign
params.auth.expires = getExpiration(5 * 60 * 1000)
// eslint-disable-next-line no-param-reassign
params = JSON.stringify(params)
signature = await sign(secret, params)
}

return { params, signature }
}
8 changes: 0 additions & 8 deletions examples/vue3/src/index.css

This file was deleted.

1 change: 0 additions & 1 deletion examples/vue3/src/main.js
@@ -1,5 +1,4 @@
import { createApp } from 'vue'
import App from './App.vue'
import './index.css'

createApp(App).mount('#app')
7 changes: 7 additions & 0 deletions examples/vue3/vite.config.js
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
})

0 comments on commit 77b351a

Please sign in to comment.