Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
38 changes: 33 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var multer = require('multer');
var upload = multer();
const express = require('express')
var path = require('path');
const os = require('os');

var appDir = path.dirname(require.main.filename);

Expand Down Expand Up @@ -136,7 +137,6 @@ async function drawUserInfo(page, userInfo) {

async function createSheet(fileName, userInfo, workInfos, year, imgData) {
const pdfDoc = await PDFDocument.load(file)

pdfDoc.registerFontkit(fontkit);
const font = await pdfDoc.embedFont(fontFile)
const signature = await pdfDoc.embedPng(imgData)
Expand Down Expand Up @@ -243,14 +243,39 @@ const sleep = (ms) => {
})
}

async function getSignature() {
function getSignatureFilePath() {
const tmpDir = os.tmpdir();
filePath = path.join(tmpDir, "workDiary-signature.png");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
최근 제가 사용하는 cli 툴들은 대부분 ~/.config/application-name 이런식으로 생성해서 사용하는것 같습니다.
tmp 폴더도 상관없긴하지만 이왕이면 폴더를 생성하거나 하면 좋을듯 합니다

return filePath;
}
function getSignatureFromFile() {
const filePath = getSignatureFilePath();
if(fs.existsSync(filePath)) {
return fs.readFileSync(filePath, { encoding: "utf-8" })
}
return "";
}

function writeSignatureFile(data) {
const filePath = getSignatureFilePath();
fs.writeFileSync(filePath, data);
}

async function getSignature(isReuseSign) {
var data = "";
if (isReuseSign === true) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

early return 으로 해주시면 가독성이 좀 올라갈것 같습니다

if (isReuseSign === false) {
  return
}
~~

data = getSignatureFromFile();
if (data !== "") {
return data;
}
}

const app = express()
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use(upload.array()); // for parsing multipart/form-data
app.use(express.static(appDir+'/public'))

var data = ""


app.post('/', (req, res) =>{
res.send("Hello")
Expand All @@ -270,11 +295,11 @@ async function getSignature() {
}

server.close()
writeSignatureFile(data);
return data
}

async function main(){
const signature = await getSignature()
var myArgs = process.argv.slice(2);
if (myArgs.length == 0) {
console.log("Usage : workDiary 'csv file path' '[year]'")
Expand All @@ -285,6 +310,9 @@ async function main(){
if (typeof year === "undefined") {
year = new Date().getFullYear().toString();
}
const reuseSign = myArgs.filter((arg) => arg === "--reuse-sign");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 위에 example이랑 Usage 에도 추가해주실 수 있을까요?

const isReuseSign = reuseSign.length > 0;
const signature = await getSignature(isReuseSign);
const [userInfo, workInfos] = await parseCSV(csvFileName);

for (var i = 0; i < workInfos.length; i++) {
Expand Down