View Single Post
  #135  
Old 20.07.2017, 12:23
Dedi
Guest
 
Posts: n/a
Thumbs up

@raztoki: Thank you for this hint. I'll try this. Cause' I normally don't need the archives within the main archive.

@mgpai/jiaz: Unfortunately the within archives are extracted after the main archive. This lead to the problem, that I can't rely on the fact that the download link of the archive is null.

So if I check the event that the main archive is extracted, the archive isn't extracted completely (extraction is still in status running), so triggering upload is not possible. When checking afterwards if the download link is null, I also don't want to trigger the upload.

So it's a bit tricky.

Spoiler:
Code:
/*
 * Executes script on any extraction event.
 *
 * @Trigger		Any Extraction Event
 * @Author		Dedi
 *
 * Possible events are:
 * - START
 * - QUEUED
 * - OPEN_ARCHIVE_SUCCESS
 * - ACTIVE_ITEM
 * - EXTRACTING
 * - FINISHED
 * - CLEANUP
 */

require("**External links are only visible to Support Staff**);
 
function getArchive() {
    return archive;
}

function getPackage() {
	return getArchive().getDownloadLinks()[0].getPackage();
}

function getDownloadLinksFromPackage() {
	return getPackage().getDownloadLinks();
}

function getExtractionQueue() {
    return callAPI("extraction", "getQueue");
}

function getUploadFolder() {
		var pattern = /(M:\\E\\[^\\]*)(.*)/g
		var match = pattern.exec(getArchive().getExtractToFolder());
		return match[0];
}

function removeExtractedFiles() {
    extractedArchiveFiles = getArchive().getExtractedFiles();
    for (var i = 0; i < extractedArchiveFiles.length; i++) {
        getPath(extractedArchiveFiles[i]).delete();
        log("Remove File: " + extractedArchiveFiles[i]);
    }
}

log("Event: " + event);

if(_.chain(getArchive().getDownloadLinks()).size() > 0) {
	if (event == "QUEUED") {
		var queue = getExtractionQueue();
		log("Queue: " + queue.length);
		if (queue.length >= 1) {
			log("Stopping downloads...");
			stopDownloads();
			log("Downloads stopped...");
		}
	}

	if (event == "FINISHED") {
		var unfinishedLinks = _.chain(getDownloadLinksFromPackage())
			.filter(function(link) {
					return link.getArchive != null && link.getExtractionStatus() == "RUNNING";
				})
			.size();
		
		log("There are " + unfinishedLinks + "links for the package " + getPackage().getName());
		
		if(unfinishedLinks <= 0) {
			var uploadFolder = getUploadFolder();

			log("Upload Folder: " + uploadFolder);
			log(callSync("M:\\rcloneUploads.cmd", uploadFolder));

			log("Remove files...");
			removeExtractedFiles();
			log("Files removed...");

			var queue = getExtractionQueue();
			log("Queue: " + queue.length);
			if (queue.length <= 0) {
				log("Start downloads...");
				startDownloads();
				log("Downloads started...");
			}
		}
	}
} else {
	log("Archive (" + getArchive().getName() + ") has no download links!");
}


THX
Reply With Quote