This commit is contained in:
Namhyeon Go 2020-11-26 13:46:44 +09:00
parent 55b88bf212
commit 3ead445d70
3 changed files with 121 additions and 198 deletions

43
lib/cookie.js Normal file
View File

@ -0,0 +1,43 @@
var CookieObject = function() {
this.expireDays = 90;
this.setExpireDays = function(days) {
this.expireDays = days;
return this;
};
this.isEnabled = function() {
return (typeof(document) !== "undefined" && typeof(document.cookie) !== "undefined");
};
this.add = function(key, value) {
if (this.isEnabled()) {
var todayDate = new Date();
todayDate.setDate(todayDate.getDate() + expiredays);
document.cookie = key + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
} else {
console.warn("CookieObject.add() -> Cookie does not supported on this environment");
}
};
this.get = function(key) {
if (this.isEnabled()) {
var result = null;
var cookie = document.cookie.split(';');
cookie.some(function (item) {
// 공백을 제거
item = item.replace(' ', '');
var dic = item.split('=');
if (key === dic[0]) {
result = dic[1];
return true; // break;
}
});
return result;
} else {
console.warn("CookieObject.add() -> Cookie does not supported on this environment");
}
};
};

View File

@ -7,14 +7,55 @@
// //
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
var LIB = require("lib/std"); var LIB = require('lib/std');
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// readFile // Private APIs / Utility functions
/////////////////////////////////////////////////////////////////////////////////
exports.VERSIONINFO = "File Lib (file.js) version 0.2";
exports.global = global;
exports.require = global.require;
/////////////////////////////////////////////////////////////////////////////////
// exports.fileExists
/////////////////////////////////////////////////////////////////////////////////
exports.fileExists = function(FN) {
var FSO = CreateObject("Scripting.FileSystemObject");
var exists = FSO.FileExists(FN);
FSO = null;
return exists;
};
/////////////////////////////////////////////////////////////////////////////////
// exports.folderExists
/////////////////////////////////////////////////////////////////////////////////
exports.folderExists = function(FN) {
var FSO = CreateObject("Scripting.FileSystemObject");
var exists = FSO.FolderExists(FN);
FSO = null;
return exists;
};
/////////////////////////////////////////////////////////////////////////////////
// exports.fileGet
/////////////////////////////////////////////////////////////////////////////////
exports.fileGet = function(FN) {
var FSO = CreateObject("Scripting.FileSystemObject");
var file = FSO.GetFile(FN);
FSO = null;
return file;
};
/////////////////////////////////////////////////////////////////////////////////
// exports.readFile
// Read the conents of the pass filename and return as a string // Read the conents of the pass filename and return as a string
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
var readFile = function(FN, charset) { exports.readFile = function(FN, charset) {
if(typeof(charset) === "undefined") { if(typeof(charset) === "undefined") {
var FSO = CreateObject("Scripting.FileSystemObject"); var FSO = CreateObject("Scripting.FileSystemObject");
var T = null; var T = null;
@ -30,27 +71,22 @@ var readFile = function(FN, charset) {
FSO = null; FSO = null;
return T; return T;
} else { } else {
try { var fsT = CreateObject("ADODB.Stream");
var fsT = CreateObject("ADODB.Stream"); fsT.CharSet = charset;
var T = null; fsT.Open();
fsT.CharSet = charset; fsT.LoadFromFile(FN);
fsT.Open(); T = fsT.ReadText();
fsT.LoadFromFile(FN); fsT = null;
T = fsT.ReadText(); return T;
fsT = null;
return T;
} catch (e) {
console.error("readFile -> ", e.message);
}
} }
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// writeFile // exports.writeFile
// Write the passed content to named disk file // Write the passed content to named disk file
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
var writeFile = function(FN, content, charset) { exports.writeFile = function(FN, content, charset) {
var Stream_No_UTF8_BOM = function(objStream) { var Stream_No_UTF8_BOM = function(objStream) {
var _objStream = CreateObject("ADODB.Stream"); var _objStream = CreateObject("ADODB.Stream");
_objStream.Type = 1; _objStream.Type = 1;
@ -98,193 +134,37 @@ var writeFile = function(FN, content, charset) {
return ok; return ok;
}; };
var FileObject = function() { /////////////////////////////////////////////////////////////////////////////////
this.interfaces = null; // exports.moveFile
this.interface = null; /////////////////////////////////////////////////////////////////////////////////
this.filename = null;
this.charset = "utf-8";
this.isExists = false;
this.isFile = false;
this.isDirectory = false;
this.setInterface = function(interfaceName) {
this.interface = this.interfaces[interfaceName];
return this;
};
this.setCharset = function(charset) {
this.charset = charset;
return this;
};
this.create = function() {
this.interfaces = {
fso: CreateObject("Scripting.FileSystemObject"),
ado: CreateObject("ADODB.Stream")
};
this.setInterface("fso");
return this;
};
this.exists = function() {
try {
if (this.interface.FileExists(this.filename)) {
this.isExists = true;
this.isFile = true;
} else if (this.interface.folderExists(this.filename)) {
this.isExists = true;
this.isDirectory = true;
}
} catch (e) {
console.error("FileObject.exists() -> ", e.message);
}
return this.isExists;
};
this.open = function(filename) {
this.filename = filename;
if (!this.exists()) {
console.warn("FileObject.open() -> The file or directory does not exists: " + this.filename);
}
return this;
};
this.getDetails = function() {
try {
if (this.isFile) {
return this.interface.GetFile(this.filename);
} else if (this.isDirectory) {
return this.interface.GetFolder(this.filename);
}
} catch (e) {
console.error("FileObject.getDetails() -> ", e.message);
}
};
this.remove = function() {
try {
if (this.isFile) {
return this.interface.DeleteFile(this.filename);
} else {
return this.interface.DeleteFolder(this.filename);
}
} catch (e) {
console.error("FileObject.remove() -> ", e.message);
}
};
this.moveTo = function(dst) {
try {
if (this.isFile) {
return this.interface.MoveFile(this.filename, dst);
} else {
return this.interface.MoveFolder(this.filename, dst);
}
} catch (e) {
console.error("FileObject.moveTo() -> ", e.message);
}
};
this.read = function() {
try {
if (this.isFile) {
return readFile(this.filename, this.charset);
}
} catch (e) {
console.error("FileObject.read() -> ", e.message);
}
};
this.write = function(content) {
try {
if (this.isFile) {
return writeFile(this.filename, content, this.charset);
}
} catch (e) {
console.error("FileObject.write() -> ", e.message);
}
};
this.chown = function(username) {
try {
if (this.isFile) {
//require("lib/shell").run(["cacls", this.filename, "/G", user + ":F"]);
require("lib/shell").run([
"icacls",
"/C",
"/q",
this.filename,
"/grant",
username + ":(F)"
]);
} else if (this.isDirectory) {
//require("lib/shell").run(["cacls", this.filename, "/G", user + ":F"]);
require("lib/shell").run([
"icacls",
"/C",
"/t",
"/q",
this.filename,
"/grant",
username + ":(F)"
]);
}
} catch (e) {
console.error("FileObject.chown() -> ", e.message);
}
};
this.mkdir = function() {
try {
if (this.isDirectory) {
return this.interface.CreateFolder(this.filename);
}
} catch (e) {
console.error("FileObject.mkdir() -> ", e.message);
}
};
this.close = function() {
this.interfaces.fso = null;
this.interfaces.ado = null;
this.interface = null;
};
this.create();
};
exports.getFile = function(FN) {
return (new FileObject()).getDetails();
};
exports.fileExists = function(FN) {
return (new FileObject()).open(FN).exists();
};
exports.folderExists = function(FN) {
return (new FileObject()).open(FN).exists();
};
exports.moveFile = function(FROM, TO) { exports.moveFile = function(FROM, TO) {
return (new FileObject()).open(FROM).moveTo(TO); var FSO = CreateObject("Scripting.FileSystemObject");
var res = FSO.MoveFile(FROM, TO);
FSO = null;
return res;
}; };
/////////////////////////////////////////////////////////////////////////////////
// exports.createFolder
/////////////////////////////////////////////////////////////////////////////////
exports.createFolder = function(FN) { exports.createFolder = function(FN) {
return (new FileObject()).open(FN).mkdir(); var FSO = CreateObject("Scripting.FileSystemObject");
var res = FSO.CreateFolder(FN);
FSO = null;
return res;
}; };
/////////////////////////////////////////////////////////////////////////////////
// exports.deleteFile
/////////////////////////////////////////////////////////////////////////////////
exports.deleteFile = function(FN) { exports.deleteFile = function(FN) {
return (new FileObject()).open(FN).remove(); var FSO = CreateObject("Scripting.FileSystemObject");
var res = FSO.DeleteFile(FN);
FSO = null;
return res;
}; };
exports.readFile = function(FN, charset) { /////////////////////////////////////////////////////////////////////////////////
return (new FileObject()).setCharset(charset).open(FN).read();
};
exports.writeFile = function(FN, content, charset) {
return (new FileObject()).setCharset(charset).open(FN).write(content);
};
exports.VERSIONINFO = "File interface (file.js) version 0.2";
exports.global = global;
exports.require = global.require;

View File

@ -21,7 +21,7 @@ exports.queryService = function(name, options) {
], ],
state: "active", // state= {active | inactive | all} state: "active", // state= {active | inactive | all}
bufsize: "1024", // bufsize= <BufferSize> bufsize: "1024", // bufsize= <BufferSize>
ri: "0" // ri= <ResumeIndex> ri: "0", // ri= <ResumeIndex>
group: "" // group= <GroupName> group: "" // group= <GroupName>
}; };