client/posts: add webm thumbs to upload form
This commit is contained in:
parent
3da4c54030
commit
0a488afbd8
3 changed files with 51 additions and 32 deletions
|
@ -171,16 +171,19 @@ a .access-key
|
||||||
background-size: cover
|
background-size: cover
|
||||||
background-position: center
|
background-position: center
|
||||||
display: inline-block
|
display: inline-block
|
||||||
img
|
|
||||||
opacity: 0
|
|
||||||
width: 100%
|
|
||||||
height: 100%
|
|
||||||
width: 20px
|
width: 20px
|
||||||
height: 20px
|
height: 20px
|
||||||
&.empty
|
&.empty
|
||||||
background-image: url('/img/transparency_grid.png')
|
background-image: url('/img/transparency_grid.png')
|
||||||
background-repeat: repeat
|
background-repeat: repeat
|
||||||
background-size: initial
|
background-size: initial
|
||||||
|
img
|
||||||
|
opacity: 0
|
||||||
|
width: 100%
|
||||||
|
height: 100%
|
||||||
|
video
|
||||||
|
width: 100%
|
||||||
|
height: 100%
|
||||||
|
|
||||||
.flexbox-dummy
|
.flexbox-dummy
|
||||||
height: 0 !important
|
height: 0 !important
|
||||||
|
|
|
@ -8,7 +8,15 @@
|
||||||
<div class='thumbnail'>
|
<div class='thumbnail'>
|
||||||
<% if (['image'].includes(ctx.uploadable.type)) { %>
|
<% if (['image'].includes(ctx.uploadable.type)) { %>
|
||||||
|
|
||||||
<%= ctx.makeThumbnail(ctx.uploadable.imageUrl) %>
|
<%= ctx.makeThumbnail(ctx.uploadable.previewUrl) %>
|
||||||
|
|
||||||
|
<% } else if (['video'].includes(ctx.uploadable.type)) { %>
|
||||||
|
|
||||||
|
<div class='thumbnail'>
|
||||||
|
<video id='video' nocontrols muted>
|
||||||
|
<source type='<%- ctx.uploadable.mimeType %>' src='<%- ctx.uploadable.previewUrl %>'/>
|
||||||
|
</video>
|
||||||
|
</div>
|
||||||
|
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,17 @@ const rowTemplate = views.getTemplate('post-upload-row');
|
||||||
|
|
||||||
let globalOrder = 0;
|
let globalOrder = 0;
|
||||||
|
|
||||||
|
function _mimeTypeToPostType(mimeType) {
|
||||||
|
return {
|
||||||
|
'application/x-shockwave-flash': 'flash',
|
||||||
|
'image/gif': 'image',
|
||||||
|
'image/jpeg': 'image',
|
||||||
|
'image/png': 'image',
|
||||||
|
'video/mp4': 'video',
|
||||||
|
'video/webm': 'video',
|
||||||
|
}[mimeType] || 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
class Uploadable extends events.EventTarget {
|
class Uploadable extends events.EventTarget {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
@ -21,8 +32,12 @@ class Uploadable extends events.EventTarget {
|
||||||
destroy() {
|
destroy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get mimeType() {
|
||||||
|
return 'application/octet-stream';
|
||||||
|
}
|
||||||
|
|
||||||
get type() {
|
get type() {
|
||||||
return 'unknown';
|
return _mimeTypeToPostType(this.mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
get key() {
|
get key() {
|
||||||
|
@ -39,14 +54,14 @@ class File extends Uploadable {
|
||||||
super();
|
super();
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
|
||||||
this._imageUrl = null;
|
this._previewUrl = null;
|
||||||
if (URL && URL.createObjectURL) {
|
if (URL && URL.createObjectURL) {
|
||||||
this._imageUrl = URL.createObjectURL(file);
|
this._previewUrl = URL.createObjectURL(file);
|
||||||
} else {
|
} else {
|
||||||
let reader = new FileReader();
|
let reader = new FileReader();
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
reader.addEventListener('load', e => {
|
reader.addEventListener('load', e => {
|
||||||
this._imageUrl = e.target.result;
|
this._previewUrl = e.target.result;
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new CustomEvent('finish', {detail: {uploadable: this}}));
|
new CustomEvent('finish', {detail: {uploadable: this}}));
|
||||||
});
|
});
|
||||||
|
@ -55,23 +70,16 @@ class File extends Uploadable {
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
if (URL && URL.createObjectURL && URL.revokeObjectURL) {
|
if (URL && URL.createObjectURL && URL.revokeObjectURL) {
|
||||||
URL.revokeObjectURL(this._imageUrl);
|
URL.revokeObjectURL(this._previewUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get type() {
|
get mimeType() {
|
||||||
return {
|
return this.file.type;
|
||||||
'application/x-shockwave-flash': 'flash',
|
|
||||||
'image/gif': 'image',
|
|
||||||
'image/jpeg': 'image',
|
|
||||||
'image/png': 'image',
|
|
||||||
'video/mp4': 'video',
|
|
||||||
'video/webm': 'video',
|
|
||||||
}[this.file.type] || 'unknown';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get imageUrl() {
|
get previewUrl() {
|
||||||
return this._imageUrl;
|
return this._previewUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
get key() {
|
get key() {
|
||||||
|
@ -90,24 +98,24 @@ class Url extends Uploadable {
|
||||||
this.dispatchEvent(new CustomEvent('finish'));
|
this.dispatchEvent(new CustomEvent('finish'));
|
||||||
}
|
}
|
||||||
|
|
||||||
get type() {
|
get mimeType() {
|
||||||
let extensions = {
|
let mime = {
|
||||||
'swf': 'flash',
|
'swf': 'application/x-shockwave-flash',
|
||||||
'jpg': 'image',
|
'jpg': 'image/jpeg',
|
||||||
'png': 'image',
|
'png': 'image/png',
|
||||||
'gif': 'image',
|
'gif': 'image/gif',
|
||||||
'mp4': 'video',
|
'mp4': 'video/mp4',
|
||||||
'webm': 'video',
|
'webm': 'video/webm',
|
||||||
};
|
};
|
||||||
for (let extension of Object.keys(extensions)) {
|
for (let extension of Object.keys(mime)) {
|
||||||
if (this.url.toLowerCase().indexOf('.' + extension) !== -1) {
|
if (this.url.toLowerCase().indexOf('.' + extension) !== -1) {
|
||||||
return extensions[extension];
|
return mime[extension];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 'unknown';
|
return 'unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
get imageUrl() {
|
get previewUrl() {
|
||||||
return this.url;
|
return this.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue