New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

converter-toless-plugin

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

converter-toless-plugin - npm Package Compare versions

Comparing version 0.0.392 to 0.0.521

9

lib/components/filter.js

@@ -0,8 +1,11 @@

"use strict";
// String.prototype.replaceAll = function ra(string, string2) {
// return this.toLowerCase().split(string.toLowerCase()).join(string2);
// }
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultFilter = void 0;
function replaceAll(strmain, str1, str2) {
return strmain.toLowerCase().split(str1.toLowerCase()).join(str2);
}
export const DefaultFilter = {
exports.DefaultFilter = {
enabled: true,

@@ -18,4 +21,4 @@ words: [

};
export default async (string, filter) => {
let _filter = filter || DefaultFilter;
exports.default = async (string, filter) => {
let _filter = filter || exports.DefaultFilter;
let _string = string;

@@ -22,0 +25,0 @@ _string = (_filter.filterWords) ? await step1(_string, _filter) : _string;

@@ -7,3 +7,4 @@ import type { Compiler } from "../../d/types";

export declare function deleteFile(filePath: string): void;
export declare function deleteDirectory(dirPath: string): Promise<unknown>;
export declare function deleteAllFilesInDirectory(dir: string): void;
export declare function getNameOf(arry: Compiler[], name: string): number;

@@ -1,4 +0,7 @@

import * as path from "path";
import * as fs from "fs";
export function getProps(name) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNameOf = exports.deleteAllFilesInDirectory = exports.deleteDirectory = exports.deleteFile = exports.getProps = void 0;
const path = require("path");
const fs = require("fs");
function getProps(name) {
const n = name.split(".");

@@ -10,4 +13,5 @@ const n2 = name.split("");

}
exports.getProps = getProps;
// delete functions
export function deleteFile(filePath) {
function deleteFile(filePath) {
fs.unlink(filePath, (err) => {

@@ -19,3 +23,10 @@ if (err) {

}
export function deleteAllFilesInDirectory(dir) {
exports.deleteFile = deleteFile;
function deleteDirectory(dirPath) {
return new Promise((solve) => {
fs.rmdir(dirPath, { recursive: true }, solve);
});
}
exports.deleteDirectory = deleteDirectory;
function deleteAllFilesInDirectory(dir) {
fs.readdir(dir, (err, files) => {

@@ -32,3 +43,4 @@ if (err)

}
export function getNameOf(arry, name) {
exports.deleteAllFilesInDirectory = deleteAllFilesInDirectory;
function getNameOf(arry, name) {
let indexofar = -1;

@@ -42,1 +54,2 @@ arry.forEach((ar, i) => {

}
exports.getNameOf = getNameOf;

@@ -1,2 +0,2 @@

import multer from "multer";
import * as multer from "multer";
interface upload_file_propies {

@@ -3,0 +3,0 @@ randomStringSize: number;

@@ -1,8 +0,10 @@

import multer from "multer";
import { getProps } from "../components/utils.js";
import mime from "mime-types";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const multer = require("multer");
const utils_js_1 = require("../components/utils.js");
const mime = require("mime-types");
// for generating random strings
import { generate as generateRandomString } from "randomstring";
const randomstring_1 = require("randomstring");
let MB = 2048;
export default function upload_file(props) {
function upload_file(props) {
var storage = multer.diskStorage({

@@ -13,4 +15,4 @@ destination: (req, file, cb) => {

filename: (req, file, cb) => {
const fileprops = getProps(file.originalname);
cb(null, `${fileprops.name}_F_${generateRandomString(props.randomStringSize)}.${mime.extension(file.mimetype)}`);
const fileprops = utils_js_1.getProps(file.originalname);
cb(null, `${fileprops.name}_F_${randomstring_1.generate(props.randomStringSize)}.${mime.extension(file.mimetype)}`);
}

@@ -26,1 +28,2 @@ });

}
exports.default = upload_file;

@@ -33,9 +33,21 @@ import { Compiler, converterOptions, Dirs, Router } from "../d/types";

* @const {compilerCommand}
* #{CompeleteInputFilePath} is the path + filename +.+ fileType
* #{CompeleteOutputFilePath} is the outputdirectory + filename +.+ filetype
* #{ComepeleteFileName} is the file name with type
* #{name} is the file name without type
* #{outputT} is the same as outputT in the object, is the output type
* #{iPath} is the input Directory path
* #{oPath} is the output Directory path
*
* @example
* //Main
*
* #{iPath}
* ->is the path for the input file
*
* #{oPath}
* ->is the path for the output folder
*
* //Costume
*
* #{name.type}
* ->is the file name with type
*
* #{name}
* ->is the file name without type
*
*
*/

@@ -45,2 +57,3 @@ Command(FileNameWT: string, compilerIndex: number): string;

compileFile(FileNameWT: string, compileIndex: number): Promise<unknown>;
zipTheOutputDirectory(name: string): Promise<unknown>;
/** this function download the file to the server **DEPRICATED** */

@@ -47,0 +60,0 @@ uploadTheFile(file: any, uploadpath: string): Promise<unknown>;

@@ -1,16 +0,19 @@

import { createRequire } from 'module';
const require = createRequire(import.meta.url);
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// for running commands
import { exec } from "child_process";
var aaa = require("child_process");
let exec = aaa.exec;
// for file controling
import * as Path from "path";
import * as fs from "fs";
const Path = require("path");
const fs = require("fs");
const { path: _dirname } = require("app-root-path");
console.log(_dirname);
// for utils
import { getNameOf, getProps, deleteFile, deleteAllFilesInDirectory } from "./components/utils.js";
const utils_js_1 = require("./components/utils.js");
// for filtering names
import filter, { DefaultFilter } from "./components/filter.js";
import { join } from 'path';
import multerConfig from "./config/multer.config.js";
const filter_js_1 = require("./components/filter.js");
const path_1 = require("path");
const multer_config_js_1 = require("./config/multer.config.js");
// for archiving
const archiver_1 = require("archiver");
const defaultProps = {

@@ -24,3 +27,2 @@ PORT: 3000,

command: `-o "#{CompeleteOutputFilePath}" -i "#{CompeleteInputFilePath}"`,
outputT: "pdf",
whitelistInputs: ["Doc", "Docx"]

@@ -36,7 +38,7 @@ },

randomStringSize: 8,
filter: DefaultFilter
filter: filter_js_1.DefaultFilter
};
const MB = 2048;
const Minute = 60000;
export default class CompilersHandler {
class CompilersHandler {
constructor(props = {}) {

@@ -59,3 +61,3 @@ this.getParams({ ...defaultProps, ...props });

// setup the uploader
let upload = multerConfig({
let upload = multer_config_js_1.default({
randomStringSize: this.randomStringSize,

@@ -120,3 +122,3 @@ fileSize: this.filesizeLimitsMB,

// setting properties
const props = getProps(file.filename);
const props = utils_js_1.getProps(file.filename);
let name = props.name;

@@ -126,3 +128,3 @@ const nameWT = name + "." + props.type;

if (this.filter.enabled)
name = await filter(name, this.filter);
name = await filter_js_1.default(name, this.filter);
// get the right compiler

@@ -145,5 +147,6 @@ const compiler = this.compilers[compileType];

// definig the output name
const newnameWT = `${name}.${compiler.outputT}`;
const newnameWT = `${name}.zip`;
// defining paths
const uploadpath = Path.join(this.inputdir, nameWT);
const outputDirPath = Path.join(this.outputdir, name);
const downloadpath = Path.join(this.outputdir, newnameWT);

@@ -155,3 +158,7 @@ const URLFILE = `/files/${newnameWT}`;

// delete the input file
await deleteFile(uploadpath);
await utils_js_1.deleteFile(uploadpath);
// zip the output folder
await this.zipTheOutputDirectory(name);
// delete the the output folder
await utils_js_1.deleteDirectory(outputDirPath);
// making url for the file

@@ -190,9 +197,21 @@ await this.makeGetReqForTheFile(URLFILE, downloadpath);

* @const {compilerCommand}
* #{CompeleteInputFilePath} is the path + filename +.+ fileType
* #{CompeleteOutputFilePath} is the outputdirectory + filename +.+ filetype
* #{ComepeleteFileName} is the file name with type
* #{name} is the file name without type
* #{outputT} is the same as outputT in the object, is the output type
* #{iPath} is the input Directory path
* #{oPath} is the output Directory path
*
* @example
* //Main
*
* #{iPath}
* ->is the path for the input file
*
* #{oPath}
* ->is the path for the output folder
*
* //Costume
*
* #{name.type}
* ->is the file name with type
*
* #{name}
* ->is the file name without type
*
*
*/

@@ -202,14 +221,14 @@ Command(FileNameWT, compilerIndex) {

const path = this.inputdir;
const pathtoOutput = this.outputdir;
const name = getProps(FileNameWT).name;
const path_name_type = `${Path.join(path, FileNameWT)}`;
const opath_name_type = `${Path.join(pathtoOutput, name)}.${compiler.outputT}`;
// commands are at top
let compilerCommand = compiler.command.replace(/#{iPath}/gi, pathtoOutput); //.replace("#{Ipath}", path)
compilerCommand = compilerCommand.replace(/#{CompeleteInputFilePath}/gi, path_name_type);
compilerCommand = compilerCommand.replace(/#{CompeleteOutputFilePath}/gi, opath_name_type);
compilerCommand = compilerCommand.replace(/#{ComepeleteFileName}/gi, FileNameWT);
compilerCommand = compilerCommand.replace(/#{outputT}/gi, compiler.outputT);
const name = utils_js_1.getProps(FileNameWT).name;
const pathtoOutput = Path.join(this.outputdir, name);
const pathToInput = Path.join(this.inputdir, FileNameWT);
const pathToInputWithType = `${Path.join(path, FileNameWT)}`;
// Main
let compilerCommand = compiler.command.replace(/#{iPath}/gi, pathToInput);
// directory path
compilerCommand = compilerCommand.replace(/#{oPath}/gi, pathtoOutput);
// costume
compilerCommand = compilerCommand.replace(/#{iPath.type}/gi, pathToInputWithType);
compilerCommand = compilerCommand.replace(/#{name}/gi, name);
compilerCommand = compilerCommand.replace(/#{oPath}/gi, pathtoOutput);
compilerCommand = compilerCommand.replace(/#{name.type}/gi, FileNameWT);
return compilerCommand;

@@ -221,5 +240,20 @@ }

const compiler = this.compilers[compileIndex];
let compilerPath = join(this.router.path("main"), compiler.CompilerPath);
let compilerPath = path_1.join(this.router.path("main"), compiler.CompilerPath);
return this.execShellCommand(`${compiler.commander} "${compilerPath}" ${command}`);
}
async zipTheOutputDirectory(name) {
return new Promise((solve, reject) => {
// input directory
const output_dir = path_1.join(this.outputdir, name);
// output file
const output = fs.createWriteStream(`${output_dir}.zip`);
// ziping technic
const archive = archiver_1.default('zip');
archive.pipe(output);
archive.directory(output_dir, false);
output.on('close', solve);
archive.on('error', reject);
archive.finalize();
});
}
/** this function download the file to the server **DEPRICATED** */

@@ -271,3 +305,3 @@ uploadTheFile(file, uploadpath) {

if (this.logInFile) {
let logfile = join(this.router.logdir, "log.txt");
let logfile = path_1.join(this.router.logdir, "log.txt");
fs.appendFile(logfile, msg, (err) => {

@@ -283,4 +317,4 @@ if (err)

const dirout = this.outputdir;
deleteAllFilesInDirectory(dirin);
deleteAllFilesInDirectory(dirout);
utils_js_1.deleteAllFilesInDirectory(dirin);
utils_js_1.deleteAllFilesInDirectory(dirout);
if (!fs.existsSync(dirin)) {

@@ -295,3 +329,3 @@ fs.mkdirSync(dirin);

getIndexByName(name) {
return getNameOf(this.compilers, name);
return utils_js_1.getNameOf(this.compilers, name);
}

@@ -308,3 +342,3 @@ /** the garbage cleaner cicle starter*/

var mtime = stats.mtime;
if (Number(new Date()) - Number(new Date(mtime)) >= this.timetoGarbageCleaner * 100) {
if (Number(new Date()) - Number(new Date(mtime)) >= this.timetoGarbageCleaner * Minute) {
fs.unlink(Path.join(_dir, file), (err) => {

@@ -336,1 +370,2 @@ if (err)

}
exports.default = CompilersHandler;
{
"name": "converter-toless-plugin",
"version": "0.0.392",
"version": "0.0.521",
"description": "this is a plugin",

@@ -17,2 +17,3 @@ "main": "./lib/index.js",

"@types/app-root-path": "^1.2.4",
"@types/archiver": "^5.1.0",
"@types/express": "^4.17.11",

@@ -27,2 +28,3 @@ "@types/mime-types": "^2.1.0",

"app-root-path": "^3.0.0",
"archiver": "5.2.0",
"child_process": "^1.0.2",

@@ -32,3 +34,4 @@ "express": "^4.17.1",

"multer": "^1.4.2",
"randomstring": "^1.1.5"
"randomstring": "^1.1.5",
"rimraf": "^3.0.2"
},

@@ -38,2 +41,2 @@ "publishConfig": {

}
}
}

@@ -5,6 +5,8 @@ import * as path from "path"

import type { Compiler } from "../../d/types"
import { Request } from "express";
export function getProps(name: string) {

@@ -27,2 +29,10 @@ const n = name.split(".");

export function deleteDirectory(dirPath: string) {
return new Promise((solve) => {
fs.rmdir(dirPath, { recursive: true }, solve)
})
}
export function deleteAllFilesInDirectory(dir: string) {

@@ -29,0 +39,0 @@ fs.readdir(dir, (err, files) => {

@@ -1,7 +0,8 @@

import multer from "multer"
import * as multer from "multer"
import { getProps } from "../components/utils.js";
import mime from "mime-types"
import * as mime from "mime-types"
// for generating random strings
import { generate as generateRandomString } from "randomstring";
import { Request } from "express";

@@ -19,6 +20,6 @@ let MB = 2048;

var storage = multer.diskStorage({
destination: (req, file, cb) => {
destination: (req: Request<any, any, any, any, Record<string, any>>, file: any, cb: (error: Error | null, filename: string) => void) => {
cb(null, props.dest)
},
filename: (req, file, cb) => {
filename: (req: Request<any, any, any, any, Record<string, any>>, file: any, cb: (error: Error | null, filename: string) => void) => {
const fileprops = getProps(file.originalname)

@@ -25,0 +26,0 @@ cb(null, `${fileprops.name}_F_${generateRandomString(props.randomStringSize)}.${mime.extension(file.mimetype)}`)

@@ -1,5 +0,4 @@

import { createRequire } from 'module';
const require = createRequire(import.meta.url);
// for running commands
import { exec } from "child_process";
var aaa = require("child_process");
let exec = aaa.exec;

@@ -21,3 +20,3 @@ // for file controling

// for utils
import { getNameOf, getProps, deleteFile, deleteAllFilesInDirectory } from "./components/utils.js";
import { getNameOf, getProps, deleteFile, deleteAllFilesInDirectory, deleteDirectory } from "./components/utils.js";

@@ -33,3 +32,7 @@ // for filtering names

// for archiving
import archiver from "archiver"
const defaultProps = {

@@ -44,3 +47,2 @@ PORT: 3000,

command: `-o "#{CompeleteOutputFilePath}" -i "#{CompeleteInputFilePath}"`,
outputT: "pdf",
whitelistInputs: ["Doc", "Docx"]

@@ -230,6 +232,7 @@ },

// definig the output name
const newnameWT = `${name}.${compiler.outputT}`;
const newnameWT = `${name}.zip`;
// defining paths
const uploadpath: string = Path.join(this.inputdir, nameWT);
const outputDirPath: string = Path.join(this.outputdir, name);
const downloadpath: string = Path.join(this.outputdir, newnameWT);

@@ -247,2 +250,8 @@ const URLFILE = `/files/${newnameWT}`;

// zip the output folder
await this.zipTheOutputDirectory(name)
// delete the the output folder
await deleteDirectory(outputDirPath);
// making url for the file

@@ -284,28 +293,61 @@ await this.makeGetReqForTheFile(URLFILE, downloadpath);

* @const {compilerCommand}
* #{CompeleteInputFilePath} is the path + filename +.+ fileType
* #{CompeleteOutputFilePath} is the outputdirectory + filename +.+ filetype
* #{ComepeleteFileName} is the file name with type
* #{name} is the file name without type
* #{outputT} is the same as outputT in the object, is the output type
* #{iPath} is the input Directory path
* #{oPath} is the output Directory path
*
* @example
* //Main
*
* #{iPath}
* ->is the path for the input file
*
* #{oPath}
* ->is the path for the output folder
*
* //Costume
*
* #{name.type}
* ->is the file name with type
*
* #{name}
* ->is the file name without type
*
*
*/
Command(FileNameWT: string, compilerIndex: number): string {
const compiler = this.compilers[compilerIndex];
const path = this.inputdir;
const pathtoOutput = this.outputdir;
const name = getProps(FileNameWT).name
const path_name_type = `${Path.join(path, FileNameWT)}`
const opath_name_type = `${Path.join(pathtoOutput, name)}.${compiler.outputT}`;
// commands are at top
let compilerCommand = compiler.command.replace(/#{iPath}/gi, pathtoOutput)//.replace("#{Ipath}", path)
compilerCommand = compilerCommand.replace(/#{CompeleteInputFilePath}/gi, path_name_type)
compilerCommand = compilerCommand.replace(/#{CompeleteOutputFilePath}/gi, opath_name_type)
compilerCommand = compilerCommand.replace(/#{ComepeleteFileName}/gi, FileNameWT)
compilerCommand = compilerCommand.replace(/#{outputT}/gi, compiler.outputT)
const name = getProps(FileNameWT).name;
const pathtoOutput = Path.join(this.outputdir, name);
const pathToInput = Path.join(this.inputdir, FileNameWT)
const pathToInputWithType = `${Path.join(path, FileNameWT)}`
// Main
let compilerCommand = compiler.command.replace(/#{iPath}/gi, pathToInput)
// directory path
compilerCommand = compilerCommand.replace(/#{oPath}/gi, pathtoOutput)
// costume
compilerCommand = compilerCommand.replace(/#{iPath.type}/gi, pathToInputWithType)
compilerCommand = compilerCommand.replace(/#{name}/gi, name)
compilerCommand = compilerCommand.replace(/#{oPath}/gi, pathtoOutput)
compilerCommand = compilerCommand.replace(/#{name.type}/gi, FileNameWT)
return compilerCommand
}
/** this function compiles a file*/

@@ -322,2 +364,26 @@ compileFile(FileNameWT: string, compileIndex: number) {

async zipTheOutputDirectory(name: string) {
return new Promise((solve, reject) => {
// input directory
const output_dir = join(this.outputdir, name)
// output file
const output = fs.createWriteStream(`${output_dir}.zip`);
// ziping technic
const archive = archiver('zip');
archive.pipe(output);
archive.directory(output_dir, false);
output.on('close', solve);
archive.on('error', reject);
archive.finalize();
})
}
/** this function download the file to the server **DEPRICATED** */

@@ -412,3 +478,3 @@ uploadTheFile(file: any, uploadpath: string) {

var mtime = stats.mtime;
if (Number(new Date()) - Number(new Date(mtime)) >= this.timetoGarbageCleaner * 100) {
if (Number(new Date()) - Number(new Date(mtime)) >= this.timetoGarbageCleaner * Minute) {
fs.unlink(Path.join(_dir, file), (err: any) => {

@@ -415,0 +481,0 @@ if (err) console.error(err)

{
"compilerOptions": {
"module": "ES2020",
"module": "CommonJS",
"target": "ESNext",

@@ -5,0 +5,0 @@ "declaration": true,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc