UNPKG

4.34 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || function (d, b) {
3 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
4 function __() { this.constructor = d; }
5 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
6};
7var job_1 = require("./job");
8var file_1 = require("./file");
9var FileJob = (function (_super) {
10 __extends(FileJob, _super);
11 /**
12 * FileJob constructor.
13 * @param e
14 * @param path
15 */
16 function FileJob(e, path) {
17 _super.call(this, e, path);
18 this.file = new file_1.File(e, path);
19 }
20 /**
21 * Get the file object.
22 * @returns {File}
23 */
24 FileJob.prototype.getFile = function () {
25 return this.file;
26 };
27 /**
28 * Get the file name.
29 * @returns {string}
30 */
31 FileJob.prototype.getName = function () {
32 return this.file.getName();
33 };
34 /**
35 * Get the file name proper.
36 * @returns {string}
37 */
38 FileJob.prototype.getNameProper = function () {
39 return this.file.getNameProper();
40 };
41 /**
42 * Get the file directory name.
43 * @returns {string}
44 */
45 FileJob.prototype.getDirname = function () {
46 return this.file.getDirname();
47 };
48 /**
49 * Get the file path.
50 * @returns {string}
51 */
52 FileJob.prototype.getPath = function () {
53 return this.file.getPath();
54 };
55 /**
56 * Set a new file path.
57 * @param path
58 */
59 FileJob.prototype.setPath = function (path) {
60 this.file.setPath(path);
61 };
62 /**
63 * Set a new file name.
64 * @param filename
65 */
66 FileJob.prototype.setName = function (filename) {
67 this.createLifeEvent("set name", this.getName(), filename);
68 this.file.setName(filename);
69 };
70 /**
71 * Get the file content type.
72 * @returns {string}
73 */
74 FileJob.prototype.getContentType = function () {
75 return this.file.getContentType();
76 };
77 /**
78 * Get the file extension.
79 * @returns {string}
80 */
81 FileJob.prototype.getExtension = function () {
82 return this.file.getExtension();
83 };
84 /**
85 * Get the file basename.
86 * @returns {string}
87 */
88 FileJob.prototype.getBasename = function () {
89 return this.file.getBasename();
90 };
91 /**
92 * Check if job is a folder.
93 * @returns {boolean}
94 */
95 FileJob.prototype.isFolder = function () {
96 return false;
97 };
98 /**
99 * Check if job is a file.
100 * @returns {boolean}
101 */
102 FileJob.prototype.isFile = function () {
103 return true;
104 };
105 /**
106 * Moves a file to a nest. This is an asynchronous method which provides a callback on completion.
107 * @param destinationNest The nest object the job will be sent to.
108 * @param callback The callback provides the updated instance of the job. Depending on the nest it was sent to, it may have been cast to a new job type. This is helpful in case you need the remote path to the job once it has been uploaded to S3, for example.
109 * #### Example
110 * ```js
111 * tunnel.run((job, nest) => {
112 * console.log("Found job " + job.getName());
113 * job.move(my_s3_bucket, (s3_job) => {
114 * // Uploaded
115 * console.log("Uploaded to " + s3_job.getPath());
116 * });
117 * });
118 * ```
119 */
120 FileJob.prototype.move = function (destinationNest, callback) {
121 var fj = this;
122 try {
123 destinationNest.take(fj, function (newJob) {
124 // fj.setPath(new_path);
125 fj.e.log(1, "Job \"" + fj.getBasename() + "\" was moved to Nest \"" + destinationNest.name + "\".", fj);
126 if (callback) {
127 callback(newJob);
128 }
129 });
130 }
131 catch (e) {
132 fj.e.log(3, "Job \"" + fj.getBasename() + "\" was not moved to Nest \"" + destinationNest.name + "\". " + e, fj);
133 if (callback) {
134 callback();
135 }
136 }
137 };
138 /**
139 * Rename the job file to a new name.
140 * @param newName
141 */
142 FileJob.prototype.rename = function (newName) {
143 var file = this.getFile();
144 file.setName(newName);
145 file.renameLocal();
146 };
147 return FileJob;
148}(job_1.Job));
149exports.FileJob = FileJob;