|
|
@@ -43,56 +43,56 @@ module.exports = function(crowi) {
|
|
|
};
|
|
|
|
|
|
lib.findDeliveryFile = function(fileId, filePath) {
|
|
|
- const cacheFile = lib.createCacheFileName(fileId);
|
|
|
-
|
|
|
- debug('find delivery file', cacheFile);
|
|
|
- if (!lib.shouldUpdateCacheFile(cacheFile)) {
|
|
|
- return cacheFile;
|
|
|
- }
|
|
|
+ // const cacheFile = lib.createCacheFileName(fileId);
|
|
|
+
|
|
|
+ // debug('find delivery file', cacheFile);
|
|
|
+ // if (!lib.shouldUpdateCacheFile(cacheFile)) {
|
|
|
+ // return cacheFile;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // const loader = require('https');
|
|
|
+
|
|
|
+ // const fileStream = fs.createWriteStream(cacheFile);
|
|
|
+ // const fileUrl = lib.generateUrl(filePath);
|
|
|
+ // debug('Load attachement file into local cache file', fileUrl, cacheFile);
|
|
|
+ // loader.get(fileUrl, function(response) {
|
|
|
+ // response.pipe(fileStream, {
|
|
|
+ // end: false
|
|
|
+ // });
|
|
|
+ // response.on('end', () => {
|
|
|
+ // fileStream.end();
|
|
|
+ // return cacheFile;
|
|
|
+ // });
|
|
|
+ // });
|
|
|
+ // };
|
|
|
|
|
|
- const loader = require('https');
|
|
|
+ // // private
|
|
|
+ // lib.createCacheFileName = function(fileId) {
|
|
|
+ // return path.join(crowi.cacheDir, `attachment-${fileId}`);
|
|
|
+ // };
|
|
|
|
|
|
- const fileStream = fs.createWriteStream(cacheFile);
|
|
|
- const fileUrl = lib.generateUrl(filePath);
|
|
|
- debug('Load attachement file into local cache file', fileUrl, cacheFile);
|
|
|
- loader.get(fileUrl, function(response) {
|
|
|
- response.pipe(fileStream, {
|
|
|
- end: false
|
|
|
- });
|
|
|
- response.on('end', () => {
|
|
|
- fileStream.end();
|
|
|
- return cacheFile;
|
|
|
- });
|
|
|
- });
|
|
|
- };
|
|
|
+ // // private
|
|
|
+ // lib.shouldUpdateCacheFile = function(filePath) {
|
|
|
+ // try {
|
|
|
+ // const stats = fs.statSync(filePath);
|
|
|
|
|
|
- // private
|
|
|
- lib.createCacheFileName = function(fileId) {
|
|
|
- return path.join(crowi.cacheDir, `attachment-${fileId}`);
|
|
|
- };
|
|
|
+ // if (!stats.isFile()) {
|
|
|
+ // debug('Cache file not found or the file is not a regular fil.');
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
|
|
|
- // private
|
|
|
- lib.shouldUpdateCacheFile = function(filePath) {
|
|
|
- try {
|
|
|
- const stats = fs.statSync(filePath);
|
|
|
-
|
|
|
- if (!stats.isFile()) {
|
|
|
- debug('Cache file not found or the file is not a regular fil.');
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- if (stats.size <= 0) {
|
|
|
- debug('Cache file found but the size is 0');
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- catch (e) {
|
|
|
- // no such file or directory
|
|
|
- debug('Stats error', e);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
+ // if (stats.size <= 0) {
|
|
|
+ // debug('Cache file found but the size is 0');
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // catch (e) {
|
|
|
+ // // no such file or directory
|
|
|
+ // debug('Stats error', e);
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // return false;
|
|
|
};
|
|
|
|
|
|
|