1 | "use strict";
|
2 | var __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 | };
|
7 | var job_1 = require("./job");
|
8 | var file_1 = require("./file");
|
9 | var node_path = require("path"), fs = require("fs");
|
10 | var FolderJob = (function (_super) {
|
11 | __extends(FolderJob, _super);
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 | function FolderJob(e, path) {
|
18 | _super.call(this, e, path);
|
19 | this.path = path;
|
20 | this.files = [];
|
21 | this.getStatistics();
|
22 |
|
23 | }
|
24 | FolderJob.prototype.getStatistics = function () {
|
25 | this.basename = node_path.basename(this.getPath());
|
26 | this.dirname = node_path.dirname(this.getPath());
|
27 | };
|
28 | |
29 |
|
30 |
|
31 |
|
32 | FolderJob.prototype.createFiles = function (callback) {
|
33 | var fl = this;
|
34 | var folder_path = this.getPath();
|
35 | fs.readdir(folder_path, function (err, items) {
|
36 | items = items.filter(function (item) { return !(/(^|\/)\.[^\/\.]/g).test(item); });
|
37 | items.forEach(function (filename) {
|
38 | var filepath = folder_path + node_path.sep + filename;
|
39 | var file = new file_1.File(fl.e, filepath);
|
40 | fl.addFile(file);
|
41 | });
|
42 | callback();
|
43 | });
|
44 | };
|
45 | |
46 |
|
47 |
|
48 |
|
49 | FolderJob.prototype.getName = function () {
|
50 | return this.getBasename();
|
51 | };
|
52 | |
53 |
|
54 |
|
55 |
|
56 | FolderJob.prototype.getBasename = function () {
|
57 | return this.basename;
|
58 | };
|
59 | |
60 |
|
61 |
|
62 |
|
63 | FolderJob.prototype.getDirname = function () {
|
64 | return this.dirname;
|
65 | };
|
66 | |
67 |
|
68 |
|
69 |
|
70 | FolderJob.prototype.getPath = function () {
|
71 | return this.path;
|
72 | };
|
73 | |
74 |
|
75 |
|
76 |
|
77 | FolderJob.prototype.setPath = function (path) {
|
78 | this.path = path;
|
79 | this.getStatistics();
|
80 | };
|
81 | |
82 |
|
83 |
|
84 |
|
85 | FolderJob.prototype.addFile = function (file) {
|
86 | this.files.push(file);
|
87 | this.e.log(0, "Adding file \"" + file.getName() + "\" to job.", this);
|
88 | };
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 | FolderJob.prototype.getFile = function (index) {
|
95 | return this.files[index];
|
96 | };
|
97 | |
98 |
|
99 |
|
100 |
|
101 | FolderJob.prototype.getFiles = function () {
|
102 | return this.files;
|
103 | };
|
104 | |
105 |
|
106 |
|
107 |
|
108 | FolderJob.prototype.count = function () {
|
109 | return this.files.length;
|
110 | };
|
111 | |
112 |
|
113 |
|
114 |
|
115 | FolderJob.prototype.getExtension = function () {
|
116 | return null;
|
117 | };
|
118 | |
119 |
|
120 |
|
121 |
|
122 | FolderJob.prototype.isFolder = function () {
|
123 | return true;
|
124 | };
|
125 | |
126 |
|
127 |
|
128 |
|
129 | FolderJob.prototype.isFile = function () {
|
130 | return false;
|
131 | };
|
132 | |
133 |
|
134 |
|
135 |
|
136 |
|
137 | FolderJob.prototype.move = function (destinationNest, callback) {
|
138 | var fj = this;
|
139 | try {
|
140 | destinationNest.take(fj, function (new_path) {
|
141 | fj.setPath(new_path);
|
142 | fj.e.log(1, "Job \"" + fj.getName() + "\" was moved to Nest \"" + destinationNest.name + "\".", fj);
|
143 | if (callback) {
|
144 | callback();
|
145 | }
|
146 | });
|
147 | }
|
148 | catch (e) {
|
149 | fj.e.log(3, "Job \"" + fj.getName() + "\" was not moved to Nest \"" + destinationNest.name + "\". " + e, fj);
|
150 | if (callback) {
|
151 | callback();
|
152 | }
|
153 | }
|
154 | };
|
155 | |
156 |
|
157 |
|
158 |
|
159 | FolderJob.prototype.rename = function (newName) {
|
160 | var fj = this;
|
161 | var new_path = fj.getDirname() + node_path.sep + newName;
|
162 | fs.renameSync(fj.getPath(), new_path);
|
163 | fj.setPath(new_path);
|
164 | };
|
165 | return FolderJob;
|
166 | }(job_1.Job));
|
167 | exports.FolderJob = FolderJob;
|