-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit the build result for local operation check
- Loading branch information
Showing
21 changed files
with
248 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
.vscode/ | ||
.serverless/ | ||
coverage/ | ||
lib/ | ||
node_modules/ | ||
|
||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function cleanupTempFiles(): Promise<void>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.cleanupTempFiles = cleanupTempFiles; | ||
var _promises = _interopRequireDefault(require("fs/promises")); | ||
var _del = _interopRequireDefault(require("del")); | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
// Removes temp files generated by LibreOffice | ||
async function cleanupTempFiles() { | ||
const files = await _promises.default.readdir(`/tmp`); | ||
for (const file of files) { | ||
if (file.endsWith('.tmp') === true || file.startsWith('OSL_PIPE')) { | ||
try { | ||
await (0, _del.default)([`/tmp/${file}`, `/tmp/${file}/*`], { | ||
force: true | ||
}); | ||
// eslint-disable-next-line no-empty | ||
} catch (error) {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export declare const DEFAULT_ARGS: string[]; | ||
export declare function convertTo(filename: string, format: string): Promise<string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.DEFAULT_ARGS = void 0; | ||
exports.convertTo = convertTo; | ||
var _child_process = _interopRequireDefault(require("child_process")); | ||
var _util = _interopRequireDefault(require("util")); | ||
var _cleanup = require("./cleanup"); | ||
var _logs = require("./logs"); | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
const exec = _util.default.promisify(_child_process.default.exec); | ||
const DEFAULT_ARGS = ['--headless', '--invisible', '--nodefault', '--view', '--nolockcheck', '--nologo', '--norestore']; | ||
exports.DEFAULT_ARGS = DEFAULT_ARGS; | ||
const LO_BINARY_PATH = process.env.LO_BINARY_PATH ?? 'libreoffice7.6'; | ||
async function convertTo(filename, format) { | ||
await (0, _cleanup.cleanupTempFiles)(); | ||
const argumentsString = DEFAULT_ARGS.join(' '); | ||
const outputFilename = filename.split(/\\ /).join(' '); | ||
const cmd = `cd /tmp && ${LO_BINARY_PATH} ${argumentsString} --convert-to ${format} --outdir /tmp '/tmp/${outputFilename}'`; | ||
let logs; | ||
|
||
// due to an unknown issue, we need to run command twice | ||
try { | ||
logs = (await exec(cmd)).stdout; | ||
} catch (e) { | ||
logs = (await exec(cmd)).stdout; | ||
} | ||
await exec(`rm '/tmp/${outputFilename}'`); | ||
await (0, _cleanup.cleanupTempFiles)(); | ||
return (0, _logs.getConvertedFilePath)(logs.toString()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './convert'; | ||
export * from './validations'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _convert = require("./convert"); | ||
Object.keys(_convert).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (key in exports && exports[key] === _convert[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _convert[key]; | ||
} | ||
}); | ||
}); | ||
var _validations = require("./validations"); | ||
Object.keys(_validations).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (key in exports && exports[key] === _validations[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _validations[key]; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function getConvertedFilePath(logs: string): string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.getConvertedFilePath = getConvertedFilePath; | ||
function getConvertedFilePath(logs) { | ||
try { | ||
return logs.match(/\/tmp\/.+->\s(\/tmp\/.+) using/)[1]; | ||
} catch (e) { | ||
const ErrorWithExtendedMessage = new Error(e); | ||
ErrorWithExtendedMessage.message += `;\tTried to parse string: "${logs}"`; | ||
throw ErrorWithExtendedMessage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function canBeConvertedToPDF(filename: string): boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.canBeConvertedToPDF = canBeConvertedToPDF; | ||
var _isVideo = _interopRequireDefault(require("is-video")); | ||
var _isImage = _interopRequireDefault(require("is-image")); | ||
var _isAudioFilepath = _interopRequireDefault(require("@shelf/is-audio-filepath")); | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
const UNSUPPORTED_FILE_EXTENSIONS = ['.chm', '.heic', '.gdoc', '.gsheet', '.gslides', '.zip', '.dwg']; | ||
function canBeConvertedToPDF(filename) { | ||
filename = filename.toLowerCase(); | ||
const isFileExtensionUnsupported = UNSUPPORTED_FILE_EXTENSIONS.some(ext => filename.endsWith(ext)); | ||
if (isFileExtensionUnsupported) { | ||
return false; | ||
} | ||
return !(0, _isImage.default)(filename) && !(0, _isVideo.default)(filename) && !(0, _isAudioFilepath.default)(filename); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function cleanupTempFiles(): Promise<void>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.cleanupTempFiles = cleanupTempFiles; | ||
var _promises = _interopRequireDefault(require("fs/promises")); | ||
var _del = _interopRequireDefault(require("del")); | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
// Removes temp files generated by LibreOffice | ||
async function cleanupTempFiles() { | ||
const files = await _promises.default.readdir(`/tmp`); | ||
for (const file of files) { | ||
if (file.endsWith('.tmp') === true || file.startsWith('OSL_PIPE')) { | ||
try { | ||
await (0, _del.default)([`/tmp/${file}`, `/tmp/${file}/*`], { | ||
force: true | ||
}); | ||
// eslint-disable-next-line no-empty | ||
} catch (error) {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export declare const DEFAULT_ARGS: string[]; | ||
export declare function convertTo(filename: string, format: string): Promise<string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.DEFAULT_ARGS = void 0; | ||
exports.convertTo = convertTo; | ||
var _child_process = _interopRequireDefault(require("child_process")); | ||
var _util = _interopRequireDefault(require("util")); | ||
var _cleanup = require("./cleanup"); | ||
var _logs = require("./logs"); | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
const exec = _util.default.promisify(_child_process.default.exec); | ||
const DEFAULT_ARGS = ['--headless', '--invisible', '--nodefault', '--view', '--nolockcheck', '--nologo', '--norestore']; | ||
exports.DEFAULT_ARGS = DEFAULT_ARGS; | ||
const LO_BINARY_PATH = process.env.LO_BINARY_PATH ?? 'libreoffice7.6'; | ||
async function convertTo(filename, format) { | ||
await (0, _cleanup.cleanupTempFiles)(); | ||
const argumentsString = DEFAULT_ARGS.join(' '); | ||
const outputFilename = filename.split(/\\ /).join(' '); | ||
const cmd = `cd /tmp && ${LO_BINARY_PATH} ${argumentsString} --convert-to ${format} --outdir /tmp '/tmp/${outputFilename}'`; | ||
let logs; | ||
|
||
// due to an unknown issue, we need to run command twice | ||
try { | ||
logs = (await exec(cmd)).stdout; | ||
} catch (e) { | ||
logs = (await exec(cmd)).stdout; | ||
} | ||
await exec(`rm '/tmp/${outputFilename}'`); | ||
await (0, _cleanup.cleanupTempFiles)(); | ||
return (0, _logs.getConvertedFilePath)(logs.toString()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './convert'; | ||
export * from './validations'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _convert = require("./convert"); | ||
Object.keys(_convert).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (key in exports && exports[key] === _convert[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _convert[key]; | ||
} | ||
}); | ||
}); | ||
var _validations = require("./validations"); | ||
Object.keys(_validations).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (key in exports && exports[key] === _validations[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _validations[key]; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function getConvertedFilePath(logs: string): string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.getConvertedFilePath = getConvertedFilePath; | ||
function getConvertedFilePath(logs) { | ||
try { | ||
return logs.match(/\/tmp\/.+->\s(\/tmp\/.+) using/)[1]; | ||
} catch (e) { | ||
const ErrorWithExtendedMessage = new Error(e); | ||
ErrorWithExtendedMessage.message += `;\tTried to parse string: "${logs}"`; | ||
throw ErrorWithExtendedMessage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function canBeConvertedToPDF(filename: string): boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.canBeConvertedToPDF = canBeConvertedToPDF; | ||
var _isVideo = _interopRequireDefault(require("is-video")); | ||
var _isImage = _interopRequireDefault(require("is-image")); | ||
var _isAudioFilepath = _interopRequireDefault(require("@shelf/is-audio-filepath")); | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
const UNSUPPORTED_FILE_EXTENSIONS = ['.chm', '.heic', '.gdoc', '.gsheet', '.gslides', '.zip', '.dwg']; | ||
function canBeConvertedToPDF(filename) { | ||
filename = filename.toLowerCase(); | ||
const isFileExtensionUnsupported = UNSUPPORTED_FILE_EXTENSIONS.some(ext => filename.endsWith(ext)); | ||
if (isFileExtensionUnsupported) { | ||
return false; | ||
} | ||
return !(0, _isImage.default)(filename) && !(0, _isVideo.default)(filename) && !(0, _isAudioFilepath.default)(filename); | ||
} |