Uname: Linux webm012.cluster130.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64
Software: Apache
PHP version: 8.0.30 [ PHP INFO ] PHP os: Linux
Server Ip: 145.239.37.162
Your Ip: 216.73.216.190
User: dreampi (1009562) | Group: users (100)
Safe Mode: OFF
Disable Function:
_dyuweyrj4,_dyuweyrj4r,dl

name : edit-uppy-plugin.js
/*
 * Because of the way Uppy is designed, we can't use onBeforeUpload to set the video_id as it does not support async.
 * So this custom plugin is used to set the video_id before the upload starts.
 *
 * @see https://uppy.io/docs/writing-plugins/#Example-of-a-custom-plugin
 */
import {UIPlugin} from '@uppy/core';

class UppyCreateVid extends UIPlugin {
	constructor(uppy, opts) {
		super(uppy, {...{}, ...opts});

		this.id = this.opts.id || 'CreateVid';
		this.type = 'modifier';
	}

	createVideo(title) {
		return new Promise((resolve, reject) => {
			const formData = new FormData();
			formData.append('title', title);
			formData.append('nonce', IUP_VIDEO.nonce);

			const options = {
				method: 'POST',
				headers: {
					Accept: 'application/json',
				},
				body: formData,
			};

			fetch(
				`${ajaxurl}?action=infinite-uploads-video-create`,
				options
			)
				.then((response) => response.json())
				.then((data) => {
					console.log(data);
					if (data.success) {
						resolve(data.data);
					} else {
						reject(data.data);
					}
				})
				.catch((error) => {
					console.log('Error:', error);
					return reject(error);
				});
		});
	}

	prepareUpload = (fileIDs) => {
		const promises = fileIDs.map((fileID) => {
			const file = this.uppy.getFile(fileID);
			//get the title from the file name and remove the extension
			const title = file.name.replace(/\.[^/.]+$/, '');

			return this.createVideo(title)
				.then((upload) => {
					console.log(`Video ${upload.VideoId} created`);
					this.opts.uploadAuth.current = {...this.opts.uploadAuth.current, [fileID]: upload};
				})
				.catch((err) => {
					this.uppy.log(
						`Video could not be created ${file.id}:`,
						'warning'
					);
					this.uppy.log(err, 'warning');
				});
		});

		const emitPreprocessCompleteForAll = () => {
			fileIDs.forEach((fileID) => {
				const file = this.uppy.getFile(fileID);
				this.uppy.emit('preprocess-complete', file);
			});
		};

		// Why emit `preprocess-complete` for all files at once, instead of
		// above when each is processed?
		// Because it leads to StatusBar showing a weird “upload 6 files” button,
		// while waiting for all the files to complete pre-processing.
		return Promise.all(promises).then(emitPreprocessCompleteForAll);
	};

	install() {
		this.uppy.addPreProcessor(this.prepareUpload);
	}

	uninstall() {
		this.uppy.removePreProcessor(this.prepareUpload);
	}
}

export default UppyCreateVid;
© 2026 GrazzMean-Shell