-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Book cover uploader, moving streams to /metadata/streams, adding jwt …
…auth from query string, auth check static metadata
- Loading branch information
Showing
18 changed files
with
376 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<template> | ||
<div class="relative rounded-sm overflow-hidden" :style="{ height: width * 1.6 + 'px', width: width + 'px', maxWidth: width + 'px', minWidth: width + 'px' }"> | ||
<div class="w-full h-full relative"> | ||
<div v-if="showCoverBg" class="bg-primary absolute top-0 left-0 w-full h-full"> | ||
<div class="w-full h-full z-0" ref="coverBg" /> | ||
</div> | ||
<img ref="cover" :src="cover" @error="imageError" @load="imageLoaded" class="w-full h-full absolute top-0 left-0" :class="showCoverBg ? 'object-contain' : 'object-cover'" /> | ||
</div> | ||
|
||
<div v-if="imageFailed" class="absolute top-0 left-0 right-0 bottom-0 w-full h-full bg-red-100" :style="{ padding: placeholderCoverPadding + 'rem' }"> | ||
<div class="w-full h-full border-2 border-error flex flex-col items-center justify-center"> | ||
<img src="/Logo.png" class="mb-2" :style="{ height: 64 * sizeMultiplier + 'px' }" /> | ||
<p class="text-center font-book text-error" :style="{ fontSize: sizeMultiplier + 'rem' }">Invalid Cover</p> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
props: { | ||
src: String, | ||
width: { | ||
type: Number, | ||
default: 120 | ||
} | ||
}, | ||
data() { | ||
return { | ||
imageFailed: false, | ||
showCoverBg: false | ||
} | ||
}, | ||
watch: { | ||
cover() { | ||
this.imageFailed = false | ||
} | ||
}, | ||
computed: { | ||
cover() { | ||
return this.src | ||
}, | ||
sizeMultiplier() { | ||
return this.width / 120 | ||
}, | ||
placeholderCoverPadding() { | ||
return 0.8 * this.sizeMultiplier | ||
} | ||
}, | ||
methods: { | ||
setCoverBg() { | ||
if (this.$refs.coverBg) { | ||
this.$refs.coverBg.style.backgroundImage = `url("${this.src}")` | ||
this.$refs.coverBg.style.backgroundSize = 'cover' | ||
this.$refs.coverBg.style.backgroundPosition = 'center' | ||
this.$refs.coverBg.style.opacity = 0.25 | ||
this.$refs.coverBg.style.filter = 'blur(1px)' | ||
} | ||
}, | ||
imageLoaded() { | ||
if (this.$refs.cover) { | ||
var { naturalWidth, naturalHeight } = this.$refs.cover | ||
var aspectRatio = naturalHeight / naturalWidth | ||
var arDiff = Math.abs(aspectRatio - 1.6) | ||
// If image aspect ratio is <= 1.45 or >= 1.75 then use cover bg, otherwise stretch to fit | ||
if (arDiff > 0.15) { | ||
this.showCoverBg = true | ||
this.$nextTick(this.setCoverBg) | ||
} else { | ||
this.showCoverBg = false | ||
} | ||
} | ||
}, | ||
imageError(err) { | ||
console.error('ImgError', err) | ||
this.imageFailed = true | ||
} | ||
}, | ||
mounted() {} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<template> | ||
<div> | ||
<input ref="fileInput" id="hidden-input" type="file" :accept="inputAccept" class="hidden" @change="inputChanged" /> | ||
<ui-btn @click="clickUpload" color="primary" type="text">Upload Cover</ui-btn> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
data() { | ||
return { | ||
inputAccept: 'image/*' | ||
} | ||
}, | ||
computed: {}, | ||
methods: { | ||
reset() { | ||
if (this.$refs.fileInput) { | ||
this.$refs.fileInput.value = '' | ||
} | ||
}, | ||
clickUpload() { | ||
if (this.$refs.fileInput) { | ||
this.$refs.fileInput.click() | ||
} | ||
}, | ||
inputChanged(e) { | ||
if (!e.target || !e.target.files) return | ||
var _files = Array.from(e.target.files) | ||
if (_files && _files.length) { | ||
var file = _files[0] | ||
console.log('File', file) | ||
this.$emit('change', file) | ||
} | ||
} | ||
}, | ||
mounted() {} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.