Showing
7 changed files
with
243 additions
and
36 deletions
... | @@ -17,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
17 | "express": "^4.18.1", | 17 | "express": "^4.18.1", |
18 | "fs": "^0.0.1-security", | 18 | "fs": "^0.0.1-security", |
19 | "localforage": "^1.10.0", | 19 | "localforage": "^1.10.0", |
20 | + "mysql": "^2.18.1", | ||
20 | "puppeteer": "^14.1.1", | 21 | "puppeteer": "^14.1.1", |
21 | "react": "^18.1.0", | 22 | "react": "^18.1.0", |
22 | "react-dom": "^18.1.0", | 23 | "react-dom": "^18.1.0", |
... | @@ -4904,6 +4905,14 @@ | ... | @@ -4904,6 +4905,14 @@ |
4904 | "node": "*" | 4905 | "node": "*" |
4905 | } | 4906 | } |
4906 | }, | 4907 | }, |
4908 | + "node_modules/bignumber.js": { | ||
4909 | + "version": "9.0.0", | ||
4910 | + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", | ||
4911 | + "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==", | ||
4912 | + "engines": { | ||
4913 | + "node": "*" | ||
4914 | + } | ||
4915 | + }, | ||
4907 | "node_modules/binary-extensions": { | 4916 | "node_modules/binary-extensions": { |
4908 | "version": "2.2.0", | 4917 | "version": "2.2.0", |
4909 | "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", | 4918 | "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", |
... | @@ -11601,6 +11610,42 @@ | ... | @@ -11601,6 +11610,42 @@ |
11601 | "multicast-dns": "cli.js" | 11610 | "multicast-dns": "cli.js" |
11602 | } | 11611 | } |
11603 | }, | 11612 | }, |
11613 | + "node_modules/mysql": { | ||
11614 | + "version": "2.18.1", | ||
11615 | + "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz", | ||
11616 | + "integrity": "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==", | ||
11617 | + "dependencies": { | ||
11618 | + "bignumber.js": "9.0.0", | ||
11619 | + "readable-stream": "2.3.7", | ||
11620 | + "safe-buffer": "5.1.2", | ||
11621 | + "sqlstring": "2.3.1" | ||
11622 | + }, | ||
11623 | + "engines": { | ||
11624 | + "node": ">= 0.6" | ||
11625 | + } | ||
11626 | + }, | ||
11627 | + "node_modules/mysql/node_modules/readable-stream": { | ||
11628 | + "version": "2.3.7", | ||
11629 | + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", | ||
11630 | + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", | ||
11631 | + "dependencies": { | ||
11632 | + "core-util-is": "~1.0.0", | ||
11633 | + "inherits": "~2.0.3", | ||
11634 | + "isarray": "~1.0.0", | ||
11635 | + "process-nextick-args": "~2.0.0", | ||
11636 | + "safe-buffer": "~5.1.1", | ||
11637 | + "string_decoder": "~1.1.1", | ||
11638 | + "util-deprecate": "~1.0.1" | ||
11639 | + } | ||
11640 | + }, | ||
11641 | + "node_modules/mysql/node_modules/string_decoder": { | ||
11642 | + "version": "1.1.1", | ||
11643 | + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", | ||
11644 | + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", | ||
11645 | + "dependencies": { | ||
11646 | + "safe-buffer": "~5.1.0" | ||
11647 | + } | ||
11648 | + }, | ||
11604 | "node_modules/nanoid": { | 11649 | "node_modules/nanoid": { |
11605 | "version": "3.3.4", | 11650 | "version": "3.3.4", |
11606 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", | 11651 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", |
... | @@ -14759,6 +14804,14 @@ | ... | @@ -14759,6 +14804,14 @@ |
14759 | "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", | 14804 | "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", |
14760 | "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" | 14805 | "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" |
14761 | }, | 14806 | }, |
14807 | + "node_modules/sqlstring": { | ||
14808 | + "version": "2.3.1", | ||
14809 | + "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz", | ||
14810 | + "integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A=", | ||
14811 | + "engines": { | ||
14812 | + "node": ">= 0.6" | ||
14813 | + } | ||
14814 | + }, | ||
14762 | "node_modules/stable": { | 14815 | "node_modules/stable": { |
14763 | "version": "0.1.8", | 14816 | "version": "0.1.8", |
14764 | "resolved": "https://registry.npmjs.org/stable/-/stable-0.1.8.tgz", | 14817 | "resolved": "https://registry.npmjs.org/stable/-/stable-0.1.8.tgz", |
... | @@ -20121,6 +20174,11 @@ | ... | @@ -20121,6 +20174,11 @@ |
20121 | "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", | 20174 | "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", |
20122 | "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==" | 20175 | "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==" |
20123 | }, | 20176 | }, |
20177 | + "bignumber.js": { | ||
20178 | + "version": "9.0.0", | ||
20179 | + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", | ||
20180 | + "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==" | ||
20181 | + }, | ||
20124 | "binary-extensions": { | 20182 | "binary-extensions": { |
20125 | "version": "2.2.0", | 20183 | "version": "2.2.0", |
20126 | "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", | 20184 | "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", |
... | @@ -24974,6 +25032,41 @@ | ... | @@ -24974,6 +25032,41 @@ |
24974 | "thunky": "^1.0.2" | 25032 | "thunky": "^1.0.2" |
24975 | } | 25033 | } |
24976 | }, | 25034 | }, |
25035 | + "mysql": { | ||
25036 | + "version": "2.18.1", | ||
25037 | + "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz", | ||
25038 | + "integrity": "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==", | ||
25039 | + "requires": { | ||
25040 | + "bignumber.js": "9.0.0", | ||
25041 | + "readable-stream": "2.3.7", | ||
25042 | + "safe-buffer": "5.1.2", | ||
25043 | + "sqlstring": "2.3.1" | ||
25044 | + }, | ||
25045 | + "dependencies": { | ||
25046 | + "readable-stream": { | ||
25047 | + "version": "2.3.7", | ||
25048 | + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", | ||
25049 | + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", | ||
25050 | + "requires": { | ||
25051 | + "core-util-is": "~1.0.0", | ||
25052 | + "inherits": "~2.0.3", | ||
25053 | + "isarray": "~1.0.0", | ||
25054 | + "process-nextick-args": "~2.0.0", | ||
25055 | + "safe-buffer": "~5.1.1", | ||
25056 | + "string_decoder": "~1.1.1", | ||
25057 | + "util-deprecate": "~1.0.1" | ||
25058 | + } | ||
25059 | + }, | ||
25060 | + "string_decoder": { | ||
25061 | + "version": "1.1.1", | ||
25062 | + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", | ||
25063 | + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", | ||
25064 | + "requires": { | ||
25065 | + "safe-buffer": "~5.1.0" | ||
25066 | + } | ||
25067 | + } | ||
25068 | + } | ||
25069 | + }, | ||
24977 | "nanoid": { | 25070 | "nanoid": { |
24978 | "version": "3.3.4", | 25071 | "version": "3.3.4", |
24979 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", | 25072 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", |
... | @@ -27132,6 +27225,11 @@ | ... | @@ -27132,6 +27225,11 @@ |
27132 | "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", | 27225 | "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", |
27133 | "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" | 27226 | "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" |
27134 | }, | 27227 | }, |
27228 | + "sqlstring": { | ||
27229 | + "version": "2.3.1", | ||
27230 | + "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz", | ||
27231 | + "integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A=" | ||
27232 | + }, | ||
27135 | "stable": { | 27233 | "stable": { |
27136 | "version": "0.1.8", | 27234 | "version": "0.1.8", |
27137 | "resolved": "https://registry.npmjs.org/stable/-/stable-0.1.8.tgz", | 27235 | "resolved": "https://registry.npmjs.org/stable/-/stable-0.1.8.tgz", | ... | ... |
... | @@ -12,6 +12,7 @@ | ... | @@ -12,6 +12,7 @@ |
12 | "express": "^4.18.1", | 12 | "express": "^4.18.1", |
13 | "fs": "^0.0.1-security", | 13 | "fs": "^0.0.1-security", |
14 | "localforage": "^1.10.0", | 14 | "localforage": "^1.10.0", |
15 | + "mysql": "^2.18.1", | ||
15 | "puppeteer": "^14.1.1", | 16 | "puppeteer": "^14.1.1", |
16 | "react": "^18.1.0", | 17 | "react": "^18.1.0", |
17 | "react-dom": "^18.1.0", | 18 | "react-dom": "^18.1.0", | ... | ... |
1 | -const fs = require("fs"); | ||
2 | - | ||
3 | function parseICal(text) { | 1 | function parseICal(text) { |
4 | const schedules = []; | 2 | const schedules = []; |
5 | let sche = {}; | 3 | let sche = {}; |
... | @@ -22,40 +20,41 @@ function parseICal(text) { | ... | @@ -22,40 +20,41 @@ function parseICal(text) { |
22 | const errArr = []; | 20 | const errArr = []; |
23 | function process(sche, k, v) { | 21 | function process(sche, k, v) { |
24 | switch (k) { | 22 | switch (k) { |
25 | - case "DTSTAMP": | ||
26 | - k = "CREATED"; | ||
27 | - v = dateTimeToDate(v); | ||
28 | - break; | ||
29 | - case "UID": | ||
30 | - v = v.split("-")[2]; | ||
31 | - break; | ||
32 | case "DTSTART": | 23 | case "DTSTART": |
33 | - k = "START"; | 24 | + sche.scheType = "time"; |
34 | - v = dateTimeToDate(v); | 25 | + sche.date = getDatestr(v); |
35 | - break; | 26 | + return; |
36 | case "DTEND": | 27 | case "DTEND": |
37 | - k = "END"; | 28 | + k = "endTime"; |
38 | - v = dateTimeToDate(v); | 29 | + v = getTimestr_z(v); |
39 | break; | 30 | break; |
40 | case "DTSTART;VALUE=DATE": | 31 | case "DTSTART;VALUE=DATE": |
41 | - case "DTEND;VALUE=DATE": | 32 | + sche.scheType = "date"; |
42 | - k = "DATE"; | 33 | + k = "date"; |
43 | - v = dateToDate(v); | 34 | + v = getDatestr(v); |
44 | break; | 35 | break; |
36 | + case "DTEND;VALUE=DATE": | ||
37 | + return; | ||
45 | case "X-ALT-DESC;FMTTYPE=text/html": | 38 | case "X-ALT-DESC;FMTTYPE=text/html": |
46 | - k = "DETAIL"; | 39 | + k = "detail"; |
47 | break; | 40 | break; |
48 | case "SUMMARY": | 41 | case "SUMMARY": |
49 | - k = "LABEL"; | 42 | + k = "label"; |
50 | - let b; | 43 | + v = v.substring(0, v.indexOf(" [")); |
51 | - [v, b] = v.split(" ["); | 44 | + break; |
52 | - sche["SUBJECT"] = b.substring(0, b.length - 1); | 45 | + case "UID": |
46 | + k = "uid"; | ||
47 | + v = v.split("-")[2]; | ||
53 | break; | 48 | break; |
49 | + case "DTSTAMP": | ||
54 | case "CLASS": | 50 | case "CLASS": |
55 | case "SEQUENCE": | 51 | case "SEQUENCE": |
56 | return; | 52 | return; |
57 | case "DESCRIPTION": | 53 | case "DESCRIPTION": |
54 | + k = "description"; | ||
58 | case "URL": | 55 | case "URL": |
56 | + k = "url"; | ||
57 | + sche.subjectID = v.substring(v.indexOf("se_") + 3, v.indexOf("&m")); | ||
59 | break; | 58 | break; |
60 | default: | 59 | default: |
61 | errArr.push(k); | 60 | errArr.push(k); |
... | @@ -70,19 +69,29 @@ function insert(str, idxs, char) { | ... | @@ -70,19 +69,29 @@ function insert(str, idxs, char) { |
70 | return nstr; | 69 | return nstr; |
71 | } | 70 | } |
72 | 71 | ||
73 | -function dateTimeToDate(str) { | 72 | +/** |
74 | - const [a, b] = str.split("T"); | 73 | + * parse DateString |
75 | - return new Date(insert(a, [4, 6, 8], "-") + "T" + insert(b, [2, 4, 6], ":")); | 74 | + * @param {string} str "YYYYMMDDTHHMMSS" |
75 | + * @returns {string} "YYYY-MM-DD" | ||
76 | + */ | ||
77 | +function getDatestr(str) { | ||
78 | + const a = str.substring(0, str.indexOf("T")); | ||
79 | + return insert(a, [4, 6, 8], "-"); | ||
76 | } | 80 | } |
77 | 81 | ||
78 | -function dateToDate(str) { | 82 | +/** |
79 | - return new Date(insert(str, [4, 6, 8], "-")); | 83 | + * parse ZDateString |
84 | + * @param {string} zstr "YYYYMMDDTHHMMSSZ" (UTC) | ||
85 | + * @returns {string} "HH:MM:SS" (UTC+9) | ||
86 | + */ | ||
87 | +function getTimestr_z(zstr) { | ||
88 | + const it = zstr.indexOf("T"); | ||
89 | + const a = zstr.substring(0, it); | ||
90 | + const b = zstr.substring(it + 1, zstr.length - 1); | ||
91 | + const date = new Date( | ||
92 | + insert(a, [4, 6, 8], "-") + "T" + insert(b, [2, 4, 6], ":") + "+00:00" | ||
93 | + ); | ||
94 | + return date.toTimeString().substring(0, 8); | ||
80 | } | 95 | } |
81 | 96 | ||
82 | -// let result; | 97 | +module.exports = parseICal; |
83 | -// fs.readFile("C:/Users/teddy/Downloads/data.ics", "utf8", (err, data) => { | ||
84 | -// if (err) console.log(err); | ||
85 | -// else result = parseICal(data); | ||
86 | -// }); | ||
87 | - | ||
88 | -export { parseICal }; | ... | ... |
server/libs/MySQL.js
0 → 100644
1 | +const mysql = require("mysql"); | ||
2 | +const fs = require("fs"); | ||
3 | +const parseICal = require("./ICal"); | ||
4 | + | ||
5 | +function jcalToSQL(jcal, userID) { | ||
6 | + const fsql = fs.readFileSync("server/libs/sql.pvdata", "utf8"); | ||
7 | + const [id, pw] = fsql.split("\r\n"); | ||
8 | + const connection = mysql.createConnection({ | ||
9 | + host: "localhost", | ||
10 | + user: id, | ||
11 | + password: pw, | ||
12 | + database: "db", | ||
13 | + }); | ||
14 | + | ||
15 | + connection.connect(); | ||
16 | + | ||
17 | + const commonCols = [ | ||
18 | + "userID", | ||
19 | + "uid", | ||
20 | + "label", | ||
21 | + "subjectID", | ||
22 | + "type", | ||
23 | + "description", | ||
24 | + "url", | ||
25 | + "detail", | ||
26 | + ]; | ||
27 | + const dateScheCols = [...commonCols, "date"]; | ||
28 | + const timeScheCols = [...commonCols, "date", "startTime", "endTime"]; | ||
29 | + const dateQueryString = | ||
30 | + "INSERT IGNORE INTO schedules_date (" + | ||
31 | + dateScheCols.join(",") + | ||
32 | + ") VALUES ?"; | ||
33 | + const timeQueryString = | ||
34 | + "INSERT IGNORE INTO schedules_time (" + | ||
35 | + timeScheCols.join(",") + | ||
36 | + ") VALUES ?"; | ||
37 | + | ||
38 | + const dateSchedules = []; | ||
39 | + const timeSchedules = []; | ||
40 | + for (const sche of jcal) { | ||
41 | + sche.userID = userID; | ||
42 | + sche.type = "assignment"; | ||
43 | + if (sche.scheType === "date") | ||
44 | + dateSchedules.push(dateScheCols.map((col) => sche[col])); | ||
45 | + else if (sche.scheType === "time") | ||
46 | + timeSchedules.push(timeScheCols.map((col) => sche[col])); | ||
47 | + else console.log("unexpected scheType", sche); | ||
48 | + } | ||
49 | + | ||
50 | + connection.query(dateQueryString, [dateSchedules], (error, result) => { | ||
51 | + if (error) console.log(error); | ||
52 | + else console.log(`schedules_date | ${result.affectedRows} rows added`); | ||
53 | + }); | ||
54 | + connection.query(timeQueryString, [timeSchedules], (error, result) => { | ||
55 | + if (error) console.log(error); | ||
56 | + else console.log(`schedules_time | ${result.affectedRows} rows added`); | ||
57 | + }); | ||
58 | + | ||
59 | + connection.end(); | ||
60 | +} | ||
61 | + | ||
62 | +// iCal의 소유주를 DB에 등록 후 userID get | ||
63 | +// subjectID가 subjects, userID가 users에 있어야함 | ||
64 | +const fdata = fs.readFileSync("C:/Users/teddy/Downloads/data.ics", "utf8"); | ||
65 | +const jcal = parseICal(fdata); | ||
66 | +jcalToSQL(jcal, 1); | ||
67 | + | ||
68 | +module.exports = jcalToSQL; |
server/routers/DB.js
0 → 100644
1 | +const express = require("express"); | ||
2 | +const mysql = require("mysql"); | ||
3 | +const fs = require("fs"); | ||
4 | +const router = express.Router(); | ||
5 | + | ||
6 | +const [id, pw] = fs | ||
7 | + .readFileSync("server/libs/sql.pvdata", "utf8") | ||
8 | + .split("\r\n"); | ||
9 | + | ||
10 | +const connection = mysql.createConnection({ | ||
11 | + host: "localhost", | ||
12 | + user: id, | ||
13 | + password: pw, | ||
14 | + database: "mydb", | ||
15 | +}); | ||
16 | + | ||
17 | +router.get("/", (req, res) => { | ||
18 | + res.send("DB Root"); | ||
19 | +}); | ||
20 | + | ||
21 | +router.get("/mytable", (req, res) => { | ||
22 | + connection.query("SELECT * from mytable", (error, rows) => { | ||
23 | + if (error) throw error; | ||
24 | + console.log(rows); | ||
25 | + res.send(rows); | ||
26 | + }); | ||
27 | +}); | ||
28 | + | ||
29 | +module.exports = router; |
... | @@ -4,7 +4,8 @@ const fs = require("fs"); | ... | @@ -4,7 +4,8 @@ const fs = require("fs"); |
4 | const cors = require("cors"); | 4 | const cors = require("cors"); |
5 | const { getPeed, getSubjects, login } = require("./libs/E_Campus.js"); | 5 | const { getPeed, getSubjects, login } = require("./libs/E_Campus.js"); |
6 | 6 | ||
7 | -const loginRouter = require("./routers/login"); | 7 | +const loginRouter = require("./routers/Login"); |
8 | +const dbRouter = require("./routers/DB"); | ||
8 | 9 | ||
9 | const app = express(); | 10 | const app = express(); |
10 | 11 | ||
... | @@ -23,6 +24,7 @@ app.post("/", (req, res) => { | ... | @@ -23,6 +24,7 @@ app.post("/", (req, res) => { |
23 | }); | 24 | }); |
24 | 25 | ||
25 | app.use("/login", loginRouter); | 26 | app.use("/login", loginRouter); |
27 | +app.use("/db", dbRouter); | ||
26 | 28 | ||
27 | // fs.readFile("server/libs/login.pvdata", "utf8", async (err, data) => { | 29 | // fs.readFile("server/libs/login.pvdata", "utf8", async (err, data) => { |
28 | // if (err) { | 30 | // if (err) { | ... | ... |
-
Please register or login to post a comment