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vimeo-upload-privacy2@1.0.1/vimeo-upload.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/*\n | Vimeo-Upload: Upload videos to your Vimeo account directly from a\n |               browser or a Node.js app\n |\n |  ╭───╮╭─╮\n |  │   ││ │╭─╮╭──┬──┬─╮╭───╮╭───╮\n |  │   ││ │├─┤│ ╭╮ ╭╮ ││ ─ ││╭╮ │  ╭────────┬─────────────────────╮\n |  ╰╮  ╰╯╭╯│ ││ ││ ││ ││  ─┤│╰╯ │  | UPLOAD │ ▒▒▒▒▒▒▒▒▒▒▒░░░░ %75 |\n |   ╰────╯ ╰─╯╰─╯╰─╯╰─╯╰───╯╰───╯  ╰────────┴─────────────────────╯\n |\n |\n | This project was released under Apache 2.0\" license.\n |\n | @link      http://websemantics.ca\n | @author    Web Semantics, Inc. Dev Team <team@websemantics.ca>\n | @author    Adnan M.Sagar, PhD. <adnan@websemantics.ca>\n | @credits   Built on cors-upload-sample, https://github.com/googledrive/cors-upload-sample\n */\n\n;\n(function(root, factory) {\n    if (typeof define === 'function' && define.amd) {\n        define([], function() {\n            return (root.VimeoUpload = factory())\n        })\n    } else if (typeof module === 'object' && module.exports) {\n        module.exports = factory()\n    } else {\n        root.VimeoUpload = factory()\n    }\n}(this, function() {\n    var attempts = 0\n    // -------------------------------------------------------------------------\n    // RetryHandler Class\n\n    /**\n     * Helper for implementing retries with backoff. Initial retry\n     * delay is 1 second, increasing by 2x (+jitter) for subsequent retries\n     *\n     * @constructor\n     */\n    var RetryHandler = function() {\n        this.interval = 1000 // Start at one second\n        this.maxInterval = 60 * 1000; // Don't wait longer than a minute\n    }\n\n    /**\n     * Invoke the function after waiting\n     *\n     * @param {function} fn Function to invoke\n     */\n    RetryHandler.prototype.retry = function(fn) {\n        setTimeout(fn, this.interval)\n        this.interval = this.nextInterval_()\n    }\n\n    /**\n     * Reset the counter (e.g. after successful request)\n     */\n    RetryHandler.prototype.reset = function() {\n        this.interval = 1000\n    }\n\n    /**\n     * Calculate the next wait time.\n     * @return {number} Next wait interval, in milliseconds\n     *\n     * @private\n     */\n    RetryHandler.prototype.nextInterval_ = function() {\n        var interval = this.interval * 2 + this.getRandomInt_(0, 1000)\n        return Math.min(interval, this.maxInterval)\n    }\n\n    /**\n     * Get a random int in the range of min to max. Used to add jitter to wait times.\n     *\n     * @param {number} min Lower bounds\n     * @param {number} max Upper bounds\n     * @private\n     */\n    RetryHandler.prototype.getRandomInt_ = function(min, max) {\n        return Math.floor(Math.random() * (max - min + 1) + min)\n    }\n\n    // -------------------------------------------------------------------------\n    // Private data\n\n    /* Library defaults, can be changed using the 'defaults' member method,\n\n    - api_url (string), vimeo api url\n    - name (string), default video name\n    - description (string), default video description\n    - contentType (string), video content type\n    - token (string), vimeo api token\n    - file (object), video file\n    - metadata (array), data to associate with the video\n    - upgrade_to_1080 (boolean), set video resolution to high definition\n    - offset (int),\n    - chunkSize (int),\n    - retryHandler (RetryHandler), hanlder class\n    - onComplete (function), handler for onComplete event\n    - onProgress (function), handler for onProgress event\n    - onError (function), handler for onError event\n\n    */\n\n    var defaults = {\n        api_url: 'https://api.vimeo.com',\n        name: 'Default name',\n        description: 'Default description',\n        privacy: 'anybody',\n        contentType: 'application/octet-stream',\n        token: null,\n        file: {},\n        metadata: [],\n        upgrade_to_1080: false,\n        offset: 0,\n        chunkSize: 0,\n        retryHandler: new RetryHandler(),\n        onComplete: function() {},\n        onProgress: function() {},\n        onError: function() {}\n    }\n\n    /**\n     * Helper class for resumable uploads using XHR/CORS. Can upload any Blob-like item, whether\n     * files or in-memory constructs.\n     *\n     * @example\n     * var content = new Blob([\"Hello world\"], {\"type\": \"text/plain\"})\n     * var uploader = new VimeoUpload({\n     *   file: content,\n     *   token: accessToken,\n     *   onComplete: function(data) { ... }\n     *   onError: function(data) { ... }\n     * })\n     * uploader.upload()\n     *\n     * @constructor\n     * @param {object} options Hash of options\n     * @param {string} options.token Access token\n     * @param {blob} options.file Blob-like item to upload\n     * @param {string} [options.fileId] ID of file if replacing\n     * @param {object} [options.params] Additional query parameters\n     * @param {string} [options.contentType] Content-type, if overriding the type of the blob.\n     * @param {object} [options.metadata] File metadata\n     * @param {function} [options.onComplete] Callback for when upload is complete\n     * @param {function} [options.onProgress] Callback for status for the in-progress upload\n     * @param {function} [options.onError] Callback if upload fails\n     */\n    var me = function(opts) {\n\n        /* copy user options or use default values */\n        for (var i in defaults) {\n            this[i] = (opts[i] !== undefined) ? opts[i] : defaults[i]\n        }\n\n        this.contentType = opts.contentType || this.file.type || defaults.contentType\n        this.httpMethod = opts.fileId ? 'PUT' : 'POST'\n\n        this.videoData = {\n            name: (opts.name > '') ? opts.name : defaults.name,\n            description: (opts.description > '') ? opts.description : defaults.description,\n            'privacy.view': (opts.privacy > '') ? opts.privacy : defaults.privacy\n        }\n\n        if (!(this.url = opts.url)) {\n            var params = opts.params || {} /*  TODO params.uploadType = 'resumable' */\n            this.url = this.buildUrl_(opts.fileId, params, opts.baseUrl)\n        }\n    }\n\n    // -------------------------------------------------------------------------\n    // Public methods\n\n    /*\n      Override class defaults\n\n        Parameters:\n        - opts (object): name value pairs\n\n    */\n\n    me.prototype.defaults = function(opts) {\n        return defaults /* TODO $.extend(true, defaults, opts) */\n    }\n\n    /**\n     * Initiate the upload (Get vimeo ticket number and upload url)\n     */\n    me.prototype.upload = function() {\n        var xhr = new XMLHttpRequest()\n        xhr.open(this.httpMethod, this.url, true)\n        xhr.setRequestHeader('Authorization', 'Bearer ' + this.token)\n        xhr.setRequestHeader('Content-Type', 'application/json')\n\n        xhr.onload = function(e) {\n            // get vimeo upload  url, user (for available quote), ticket id and complete url\n            if (e.target.status < 400) {\n                var response = JSON.parse(e.target.responseText)\n                this.url = response.upload_link_secure\n                this.user = response.user\n                this.ticket_id = response.ticket_id\n                this.complete_url = defaults.api_url + response.complete_uri\n                this.sendFile_()\n            } else {\n                this.onUploadError_(e)\n            }\n        }.bind(this)\n\n        xhr.onerror = this.onUploadError_.bind(this)\n        xhr.send(JSON.stringify({\n            type: 'streaming',\n            upgrade_to_1080: this.upgrade_to_1080\n        }))\n    }\n\n    // -------------------------------------------------------------------------\n    // Private methods\n\n    /**\n     * Send the actual file content.\n     *\n     * @private\n     */\n    me.prototype.sendFile_ = function() {\n        var content = this.file\n        var end = this.file.size\n\n        if (this.offset || this.chunkSize) {\n            // Only bother to slice the file if we're either resuming or uploading in chunks\n            if (this.chunkSize) {\n                end = Math.min(this.offset + this.chunkSize, this.file.size)\n            }\n            content = content.slice(this.offset, end)\n        }\n\n        var xhr = new XMLHttpRequest()\n        xhr.open('PUT', this.url, true)\n        xhr.setRequestHeader('Content-Type', this.contentType)\n            // xhr.setRequestHeader('Content-Length', this.file.size)\n        xhr.setRequestHeader('Content-Range', 'bytes ' + this.offset + '-' + (end - 1) + '/' + this.file.size)\n\n        if (xhr.upload) {\n            xhr.upload.addEventListener('progress', this.onProgress)\n        }\n        xhr.onload = this.onContentUploadSuccess_.bind(this)\n        xhr.onerror = this.onContentUploadError_.bind(this)\n        xhr.send(content)\n    }\n\n    /**\n     * Query for the state of the file for resumption.\n     *\n     * @private\n     */\n    me.prototype.resume_ = function() {\n        var xhr = new XMLHttpRequest()\n        xhr.open('PUT', this.url, true)\n        xhr.setRequestHeader('Content-Range', 'bytes */' + this.file.size)\n        xhr.setRequestHeader('X-Upload-Content-Type', this.file.type)\n        if (xhr.upload) {\n            xhr.upload.addEventListener('progress', this.onProgress)\n        }\n        xhr.onload = this.onContentUploadSuccess_.bind(this)\n        xhr.onerror = this.onContentUploadError_.bind(this)\n        xhr.send()\n    }\n\n    /**\n     * Extract the last saved range if available in the request.\n     *\n     * @param {XMLHttpRequest} xhr Request object\n     */\n    me.prototype.extractRange_ = function(xhr) {\n        var range = xhr.getResponseHeader('Range')\n        if (range) {\n            this.offset = parseInt(range.match(/\\d+/g).pop(), 10) + 1\n        }\n    }\n\n    /**\n     * The final step is to call vimeo.videos.upload.complete to queue up\n     * the video for transcoding.\n     *\n     * If successful call 'onUpdateVideoData_'\n     *\n     * @private\n     */\n    me.prototype.complete_ = function(xhr) {\n        var xhr = new XMLHttpRequest()\n        xhr.open('DELETE', this.complete_url, true)\n        xhr.setRequestHeader('Authorization', 'Bearer ' + this.token)\n\n        xhr.onload = function(e) {\n\n            // Get the video location (videoId)\n            if (e.target.status < 400) {\n                var location = e.target.getResponseHeader('Location')\n\n                // Example of location: ' /videos/115365719', extract the video id only\n                var video_id = location.split('/').pop()\n                    // Update the video metadata\n                this.onUpdateVideoData_(video_id)\n            } else {\n                this.onCompleteError_(e)\n            }\n        }.bind(this)\n\n        xhr.onerror = this.onCompleteError_.bind(this)\n        xhr.send()\n    }\n\n    /**\n     * Update the Video Data and add the metadata to the upload object\n     *\n     * @private\n     * @param {string} [id] Video Id\n     */\n    me.prototype.onUpdateVideoData_ = function(video_id) {\n        var url = this.buildUrl_(video_id, [], defaults.api_url + '/videos/')\n        var httpMethod = 'PATCH'\n        var xhr = new XMLHttpRequest()\n\n        xhr.open(httpMethod, url, true)\n        xhr.setRequestHeader('Authorization', 'Bearer ' + this.token)\n        xhr.onload = function(e) {\n            // add the metadata\n            this.onGetMetadata_(e, video_id)\n        }.bind(this)\n        xhr.setRequestHeader('Content-Type', 'text/html')\n        xhr.send(this.buildQuery_(this.videoData))\n    }\n\n    /**\n     * Retrieve the metadata from a successful onUpdateVideoData_ response\n     * This is is useful when uploading unlisted videos as the URI has changed.\n     *\n     * If successful call 'onUpdateVideoData_'\n     *\n     * @private\n     * @param {object} e XHR event\n     * @param {string} [id] Video Id\n     */\n    me.prototype.onGetMetadata_ = function(e, video_id) {\n        // Get the video location (videoId)\n        if (e.target.status < 400) {\n            if (e.target.response) {\n                // add the returned metadata to the metadata array\n                var meta = JSON.parse(e.target.response)\n                    // get the new index of the item\n                var index = this.metadata.push(meta) - 1\n                    // call the complete method\n                this.onComplete(video_id, index)\n            } else {\n                this.onCompleteError_(e)\n            }\n        }\n    }\n\n    /**\n     * Handle successful responses for uploads. Depending on the context,\n     * may continue with uploading the next chunk of the file or, if complete,\n     * invokes vimeo complete service.\n     *\n     * @private\n     * @param {object} e XHR event\n     */\n    me.prototype.onContentUploadSuccess_ = function(e) {\n        if (e.target.status == 200 || e.target.status == 201) {\n            this.complete_()\n        } else if (e.target.status == 308) {\n            this.extractRange_(e.target)\n            this.retryHandler.reset()\n            this.sendFile_()\n        }\n    }\n\n    /**\n     * Handles errors for uploads. Either retries or aborts depending\n     * on the error.\n     *\n     * @private\n     * @param {object} e XHR event\n     */\n    me.prototype.onContentUploadError_ = function(e) {\n        if ((e.target.status && e.target.status < 500) || this.offset === 0 || attempts === 5) {\n            attempts = 0\n            this.onError(e.target.response)\n        } else {\n            attempts += 1\n            this.retryHandler.retry(this.resume_())\n        }\n    }\n\n    /**\n     * Handles errors for the complete request.\n     *\n     * @private\n     * @param {object} e XHR event\n     */\n    me.prototype.onCompleteError_ = function(e) {\n        this.onError(e.target.response); // TODO - Retries for initial upload\n    }\n\n    /**\n     * Handles errors for the initial request.\n     *\n     * @private\n     * @param {object} e XHR event\n     */\n    me.prototype.onUploadError_ = function(e) {\n        this.onError(e.target.response); // TODO - Retries for initial upload\n    }\n\n    /**\n     * Construct a query string from a hash/object\n     *\n     * @private\n     * @param {object} [params] Key/value pairs for query string\n     * @return {string} query string\n     */\n    me.prototype.buildQuery_ = function(params) {\n        params = params || {}\n        return Object.keys(params).map(function(key) {\n            return encodeURIComponent(key) + '=' + encodeURIComponent(params[key])\n        }).join('&')\n    }\n\n    /**\n     * Build the drive upload URL\n     *\n     * @private\n     * @param {string} [id] File ID if replacing\n     * @param {object} [params] Query parameters\n     * @return {string} URL\n     */\n    me.prototype.buildUrl_ = function(id, params, baseUrl) {\n        var url = baseUrl || defaults.api_url + '/me/videos'\n        if (id) {\n            url += id\n        }\n        var query = this.buildQuery_(params)\n        if (query) {\n            url += '?' + query\n        }\n        return url\n    }\n\n    return me\n}))\n"]}