Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin_nodeにランダムUUID生成、ランダム配列生成命令を追加 #1888

Merged
merged 1 commit into from
Dec 26, 2024
Merged
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
64 changes: 64 additions & 0 deletions src/plugin_node.mts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function fileExists (f: string): boolean {
try {
fs.statSync(f)
return true
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
return false
}
Expand All @@ -38,6 +39,7 @@ function isDir (f: string): boolean {
try {
const st = fs.statSync(f)
return st.isDirectory()
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
return false
}
Expand Down Expand Up @@ -174,6 +176,7 @@ export default {
data = ''
})
if (handler !== undefined) { return true }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return new Promise((resolve, _reject) => {
const timerCallback = () => {
if (sys.tags.readBuffers.length > 0) {
Expand Down Expand Up @@ -211,6 +214,7 @@ export default {
type: 'func',
josi: [['を', 'から']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (s: string, sys: NakoSystem) {
return fs.readFileSync(s)
}
Expand Down Expand Up @@ -242,6 +246,7 @@ export default {
type: 'func',
josi: [['を', 'から']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (s: string, sys: NakoSystem) {
// iconv.skipDecodeWarning = true
const buf = fs.readFileSync(s)
Expand All @@ -253,6 +258,7 @@ export default {
type: 'func',
josi: [['を'], ['へ', 'に']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (s: string, f: string, sys: NakoSystem) {
// iconv.skipDecodeWarning = true
const buf = iconv.encode(s, 'Shift_JIS')
Expand All @@ -264,6 +270,7 @@ export default {
type: 'func',
josi: [['を', 'から']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (s: string, sys: NakoSystem) {
const buf = fs.readFileSync(s)
const text = iconv.decode(Buffer.from(buf), 'euc-jp')
Expand All @@ -274,6 +281,7 @@ export default {
type: 'func',
josi: [['を'], ['へ', 'に']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (s: string, f: string, sys: NakoSystem) {
const buf = iconv.encode(s, 'euc-jp')
fs.writeFileSync(f, buf)
Expand Down Expand Up @@ -305,6 +313,7 @@ export default {
type: 'func',
josi: [['で'], ['を']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (callback: any, s: string, sys: NakoSystem) {
exec(s, (err, stdout, stderr) => {
if (err) { throw new Error(stderr) } else { callback(stdout) }
Expand Down Expand Up @@ -368,6 +377,7 @@ export default {
let st: fs.Stats
try {
st = fs.statSync(fullpath)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
continue
}
Expand Down Expand Up @@ -411,6 +421,7 @@ export default {
type: 'func',
josi: [['から', 'を'], ['に', 'へ']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (a: string, b: string, sys: NakoSystem) {
return fse.copySync(a, b)
}
Expand All @@ -419,6 +430,7 @@ export default {
type: 'func',
josi: [['で'], ['から', 'を'], ['に', 'へ']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (callback: any, a: string, b: string, sys: NakoSystem) {
return fse.copy(a, b, (err: any) => {
if (err) { throw new Error('ファイルコピー時:' + err) }
Expand All @@ -431,6 +443,7 @@ export default {
type: 'func',
josi: [['から', 'を'], ['に', 'へ']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (a: string, b: string, sys: NakoSystem) {
return fse.moveSync(a, b)
}
Expand All @@ -439,6 +452,7 @@ export default {
type: 'func',
josi: [['で'], ['から', 'を'], ['に', 'へ']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (callback: any, a: string, b: string, sys: NakoSystem) {
fse.move(a, b, (err: any) => {
if (err) { throw new Error('ファイル移動時:' + err) }
Expand All @@ -451,6 +465,7 @@ export default {
type: 'func',
josi: [['の', 'を']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (path: string, sys: NakoSystem) {
return fse.removeSync(path)
}
Expand All @@ -459,6 +474,7 @@ export default {
type: 'func',
josi: [['で'], ['の', 'を']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (callback: any, path: string, sys: NakoSystem) {
return fse.remove(path, (err: any) => {
if (err) { throw new Error('ファイル削除時:' + err) }
Expand All @@ -471,6 +487,7 @@ export default {
type: 'func',
josi: [['の', 'から']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (path: string, sys: NakoSystem) {
return fs.statSync(path)
}
Expand All @@ -479,6 +496,7 @@ export default {
type: 'func',
josi: [['の', 'から']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (path: string, sys: NakoSystem) {
const st = fs.statSync(path)
if (!st) { return -1 }
Expand Down Expand Up @@ -594,6 +612,7 @@ export default {
type: 'func',
josi: [],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (sys: NakoSystem) {
// 環境変数からテンポラリフォルダを取得
return os.tmpdir()
Expand All @@ -603,6 +622,7 @@ export default {
type: 'func',
josi: [['に', 'へ']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (dir: string, sys: NakoSystem) {
if (dir === '' || !dir) {
dir = os.tmpdir()
Expand Down Expand Up @@ -661,6 +681,7 @@ export default {
a = sys.tags.__quotePath(a)
b = sys.tags.__quotePath(b)
const cmd = `${tpath} x ${a} -o${b} -y`
// eslint-disable-next-line @typescript-eslint/no-unused-vars
exec(cmd, (err, stdout, stderr) => {
if (err) { throw new Error('[エラー]『解凍時』' + err) }
callback(stdout)
Expand Down Expand Up @@ -690,6 +711,7 @@ export default {
a = sys.tags.__quotePath(a)
b = sys.tags.__quotePath(b)
const cmd = `${tpath} a -r ${b} ${a} -y`
// eslint-disable-next-line @typescript-eslint/no-unused-vars
exec(cmd, (err, stdout, stderr) => {
if (err) { throw new Error('[エラー]『圧縮時』' + err) }
callback(stdout)
Expand All @@ -715,6 +737,7 @@ export default {
if (typeof (func) === 'string') {
func = sys.__findFunc(func, '強制終了時')
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
nodeProcess.on('SIGINT', (signal: any) => {
const flag = func(sys)
if (flag) { nodeProcess.exit() }
Expand All @@ -735,6 +758,7 @@ export default {
type: 'func',
josi: [],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (sys: NakoSystem) {
return nodeProcess.platform
}
Expand All @@ -743,6 +767,7 @@ export default {
type: 'func',
josi: [],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (sys: NakoSystem) {
return nodeProcess.arch
}
Expand Down Expand Up @@ -804,7 +829,9 @@ export default {
josi: [],
pure: true,
asyncFn: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (sys: NakoSystem): Promise<string> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return new Promise((resolve, _reject) => {
let dataStr = ''
nodeProcess.stdin.on('data', (data: any) => {
Expand All @@ -822,6 +849,7 @@ export default {
type: 'func',
josi: [['と'], ['が']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (a: any, b: any, sys: NakoSystem) {
assert.strictEqual(a, b)
}
Expand All @@ -831,6 +859,7 @@ export default {
type: 'func',
josi: [],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (sys: NakoSystem) {
const nif = os.networkInterfaces()
if (!nif) { throw new Error('『自分IPアドレス取得』でネットワークのインターフェイスが種畜できません。') }
Expand All @@ -853,6 +882,7 @@ export default {
type: 'func',
josi: [],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (sys: NakoSystem) {
const nif = os.networkInterfaces()
if (!nif) { throw new Error('『自分IPアドレス取得』でネットワークのインターフェイスが種畜できません。') }
Expand Down Expand Up @@ -1011,6 +1041,7 @@ export default {
type: 'func',
josi: [['まで', 'へ', 'に'], ['を']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (url: string, params: [key: string], sys: NakoSystem) {
const flist: Array<string> = []
for (const key in params) {
Expand All @@ -1034,6 +1065,7 @@ export default {
type: 'func',
josi: [['まで', 'へ', 'に'], ['を']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (url: string, params: any, sys: NakoSystem) {
const fd = new FormData()
for (const key in params) { fd.set(key, params[key]) }
Expand All @@ -1050,6 +1082,7 @@ export default {
type: 'func',
josi: [['から'], ['で']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (res: any, type: string, sys: NakoSystem) {
type = type.toString().toUpperCase()
if (type === 'TEXT' || type === 'テキスト') {
Expand Down Expand Up @@ -1097,6 +1130,7 @@ export default {
type: 'func',
josi: [['の', 'を']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (params: any, sys: NakoSystem) {
const flist: Array<string> = []
for (const key in params) {
Expand Down Expand Up @@ -1137,6 +1171,7 @@ export default {
josi: [['まで', 'へ', 'に'], ['を']],
pure: true,
asyncFn: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (url: any, params: any, sys: any) {
return new Promise((resolve, reject) => {
const fd = new FormData()
Expand Down Expand Up @@ -1227,6 +1262,7 @@ export default {
josi: [['へ', 'に'], ['と'], ['を']],
pure: true,
asyncFn: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: async function (token: string, imageFile: string, message: string, sys: NakoSystem) {
const lineNotifyUrl = 'https://notify-api.line.me/api/notify'
const formData = new FormData()
Expand All @@ -1251,6 +1287,7 @@ export default {
type: 'func',
josi: [['の', 'を']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (code: string, sys: NakoSystem) {
return iconv.encodingExists(code)
}
Expand All @@ -1259,6 +1296,7 @@ export default {
type: 'func',
josi: [['に', 'へ', 'を']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (str: string, sys: NakoSystem) {
// iconv.skipDecodeWarning = true
return iconv.encode(str, 'Shift_JIS')
Expand All @@ -1268,6 +1306,7 @@ export default {
type: 'func',
josi: [['から', 'を', 'で']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (buf: any, sys: NakoSystem) {
// iconv.skipDecodeWarning = true
return iconv.decode(Buffer.from(buf), 'sjis')
Expand All @@ -1277,6 +1316,7 @@ export default {
type: 'func',
josi: [['を'], ['へ', 'で']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (s: string, code: string, sys: NakoSystem) {
// iconv.skipDecodeWarning = true
return iconv.encode(s, code)
Expand All @@ -1286,6 +1326,7 @@ export default {
type: 'func',
josi: [['を'], ['から', 'で']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (buf: any, code: string, sys: NakoSystem) {
// iconv.skipDecodeWarning = true
return iconv.decode(Buffer.from(buf), code)
Expand All @@ -1296,6 +1337,7 @@ export default {
type: 'func',
josi: [],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (sys: NakoSystem) {
return crypto.getHashes()
}
Expand All @@ -1304,10 +1346,32 @@ export default {
type: 'func',
josi: [['を'], ['の'], ['で']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (s: any, alg: string, enc: any, sys: NakoSystem) {
const hashsum = crypto.createHash(alg)
hashsum.update(s)
return hashsum.digest(enc)
}
},
'ランダムUUID生成': { // @ランダムに生成された36文字のv4 UUID(文字列)を返す // @ らんだむUUIDせいせい
type: 'func',
josi: [],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (sys: NakoSystem) {
const uuid = crypto.randomUUID()
return uuid
}
},
'ランダム配列生成': { // @暗号強度の強い乱数のバイト配列(Uint8Array)を指定個数返す // @ らんだむはいれつせいせい
type: 'func',
josi: [['の']],
pure: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fn: function (cnt: number, sys: NakoSystem) {
const a = new Uint8Array(cnt)
crypto.getRandomValues(a)
return a
}
}
}
Loading