根据https://github.com/transloadit/uppy-vimeo-thing/blob/master/Vimeo.js中的代码,我有下面的课程。
恢复上传不起作用,它总是从头开始重新上传。如果我uploadUrl
从 Tus 选项中删除并将endpoint
值设置为https://master.tus.io/files/
(因此不上传到 Vimeo),则恢复上传按预期工作。仅在将上传内容发送到 Vimeo 时才会出现此问题。
查看我的开发人员工具的网络选项卡,我发现upload-offset
总是0
在将 PATCH 请求发送到 Vimeo 时,即使在恢复它(后续请求)时也是如此。
const { Plugin } = require('@uppy/core')
const mapLimit = require('promise-map-limit')
const VIMEO_API_ROOT = 'https://api.vimeo.com'
class Vimeo extends Plugin {
constructor (uppy, opts) {
super(uppy, opts)
this.name = 'Vimeo'
this.id = 'Vimeo'
this.type = 'uploader'
this.opts = Object.assign({
limit: 100
}, this.opts)
this.prepareUpload = this.prepareUpload.bind(this)
this.afterUpload = this.afterUpload.bind(this)
}
async prepareUpload (fileIDs) {
const { videoTitle } = this.opts
fileIDs.forEach((fileID) => {
this.uppy.emit('preprocess-progress', fileID, {
mode: 'indeterminate',
message: 'Creating video...'
})
})
await mapLimit(fileIDs, this.opts.limit, async (fileID) => {
const file = this.uppy.getFile(fileID)
const response = await fetch(`${VIMEO_API_ROOT}/me/videos`, {
method: 'post',
headers: {
'authorization': `Bearer ${vimeoAccessToken}`,
'content-type': 'application/json',
'accept': 'application/vnd.vimeo.*+json;version=3.4'
},
body: JSON.stringify({
upload: {
approach: 'tus',
size: file.size
},
name: videoTitle
})
})
const { upload, link, uri } = await response.json()
this.uppy.setFileState(fileID, {
uploadURL: link,
vimeo: {
link,
id: uri.split('/').pop()
},
tus: Object.assign({}, file.tus, {
endpoint: 'https://files.tus.vimeo.com/files/', // HACK this is to appease tus-js-client
// NOTE: This is uploadUrl instead of endpoint, different from what you might expect;
// Vimeo pre-creates the Tus upload.
uploadUrl: upload.upload_link,
headers: {
'Accept': 'application/vnd.vimeo.*+json;version=3.4'
}
}),
})
this.uppy.emit('preprocess-complete', fileID)
})
}
async afterUpload (fileIDs) {
fileIDs.forEach((fileID) => {
const file = this.uppy.getFile(fileID)
const video = file.vimeo
this.uppy.setFileState(fileID, {
uploadURL: video.link
})
})
}
install () {
this.uppy.addPreProcessor(this.prepareUpload)
this.uppy.addPostProcessor(this.afterUpload)
}
uninstall () {
this.uppy.removePreProcessor(this.prepareUpload)
this.uppy.removePostProcessor(this.afterUpload)
}
}
module.exports = Vimeo