@clhs-api/core
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -8,3 +8,2 @@ 'use strict'; | ||
var axios = _interopDefault(require('axios')); | ||
var neverthrow = require('neverthrow'); | ||
var url = require('url'); | ||
@@ -924,3 +923,3 @@ | ||
var newsContentQuery = /*#__PURE__*/function () { | ||
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(id) { | ||
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(id, cb) { | ||
var uid, _yield$axios$get, _yield$axios$get$data, data, _, content; | ||
@@ -944,5 +943,3 @@ | ||
_context.t0 = _context["catch"](0); | ||
return _context.abrupt("return", neverthrow.err({ | ||
error: _context.t0 | ||
})); | ||
return _context.abrupt("return", cb({}, _context.t0)); | ||
@@ -964,27 +961,15 @@ case 9: | ||
return _context.abrupt("return", neverthrow.err({ | ||
error: "there's no data in the response object." | ||
})); | ||
return _context.abrupt("return", cb({}, "there's no data in the response object.")); | ||
case 17: | ||
content = data.content; | ||
_context.prev = 18; | ||
data.content = !!!content ? content : decodeURIComponent(content); | ||
_context.next = 25; | ||
break; | ||
case 22: | ||
_context.prev = 22; | ||
_context.t1 = _context["catch"](18); | ||
return _context.abrupt("return", neverthrow.ok({ | ||
data: data, | ||
warn: "error occurred while decoding the content." | ||
})); | ||
try { | ||
data.content = !!!content ? content : decodeURIComponent(content); | ||
} catch (e) {// unable to decode some of the content, ignore this for now. | ||
} | ||
case 25: | ||
return _context.abrupt("return", neverthrow.ok({ | ||
data: data | ||
})); | ||
return _context.abrupt("return", cb(data)); | ||
case 26: | ||
case 20: | ||
case "end": | ||
@@ -994,6 +979,6 @@ return _context.stop(); | ||
} | ||
}, _callee, null, [[0, 6], [18, 22]]); | ||
}, _callee, null, [[0, 6]]); | ||
})); | ||
return function newsContentQuery(_x) { | ||
return function newsContentQuery(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
@@ -1034,3 +1019,3 @@ }; | ||
var newsListQuery = /*#__PURE__*/function () { | ||
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(queryInput) { | ||
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(queryInput, cb) { | ||
var params, _yield$axios$post, queryResult, queryMeta, newsList; | ||
@@ -1060,5 +1045,3 @@ | ||
return _context.abrupt("return", neverthrow.err({ | ||
error: "error from clhs api(might be wrong input type). error message: " + queryResult | ||
})); | ||
return _context.abrupt("return", cb({}, "error from clhs api(might be wrong input type). error message: " + queryResult)); | ||
@@ -1074,12 +1057,8 @@ case 7: | ||
return _context.abrupt("return", neverthrow.err({ | ||
error: "no news can be found." | ||
})); | ||
return _context.abrupt("return", cb({}, "no news can be found.")); | ||
case 11: | ||
return _context.abrupt("return", neverthrow.ok({ | ||
data: { | ||
queryMeta: queryMeta, | ||
newsList: newsList | ||
} | ||
return _context.abrupt("return", cb({ | ||
queryMeta: queryMeta, | ||
newsList: newsList | ||
})); | ||
@@ -1095,3 +1074,3 @@ | ||
return function newsListQuery(_x) { | ||
return function newsListQuery(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
@@ -1098,0 +1077,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=(t=require("axios"))&&"object"==typeof t&&"default"in t?t.default:t,r=require("neverthrow"),n=require("url");function o(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function i(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var a=t.apply(e,r);function u(t){o(a,n,i,u,c,"next",t)}function c(t){o(a,n,i,u,c,"throw",t)}u(void 0)}))}}function a(t,e){return t(e={exports:{}},e.exports),e.exports}var u=a((function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var o=Object.create((e&&e.prototype instanceof h?e:h).prototype),i=new L(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=m(a,r);if(u){if(u===f)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=s(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(t,r,i),o}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var f={};function h(){}function l(){}function d(){}var p={};u(p,o,(function(){return this}));var _=Object.getPrototypeOf,v=_&&_(_(k([])));v&&v!==e&&r.call(v,o)&&(p=v);var y=d.prototype=h.prototype=Object.create(p);function w(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function g(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,u){var c=s(t[o],t,i);if("throw"!==c.type){var f=c.arg,h=f.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):e.resolve(h).then((function(t){f.value=t,a(f)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function m(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,m(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function b(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function k(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:E}}function E(){return{value:void 0,done:!0}}return l.prototype=d,u(y,"constructor",d),u(d,"constructor",l),l.displayName=u(d,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,a,"GeneratorFunction")),t.prototype=Object.create(y),t},t.awrap=function(t){return{__await:t}},w(g.prototype),u(g.prototype,i,(function(){return this})),t.AsyncIterator=g,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new g(c(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(y),u(y,a,"Generator"),u(y,o,(function(){return this})),u(y,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=k,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),x(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;x(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:k(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}})),c=function(t,e){return e?"https://www.clhs.tyc.edu.tw/ischool/widget/site_news/news_query_json_content.php?nid="+t+"&dir=0&uid="+e:"https://www.clhs.tyc.edu.tw/ischool/public/news_view/show.php?nid="+t},s={UID:{"首頁":"WID_549_2_3e2e399a2649fb6ba9918090490f4741fd4453bf","升學資訊":"WID_549_2_13cfc702096566ef38571aebe89498c49f56f236","法令公告":"WID_549_2_09b16f4944d742185cf599bb45ca292da6547c9e","校內競賽":"WID_549_2_c0df1de1135dbf425a0f988515224a49c98ad257","校外競賽":"WID_549_2_5d8f79c34d01e52061f469da52357fe253c45db9","新生專區":"WID_284_2_74ade31d9f46e4440ca9b60301b5f651004cec49","衛生保健":"WID_549_2_5cd5617d2dd2bc130e7f76c333f2d442dffd0681","營隊研習":"WID_549_2_0470a8e2b5755791156cb8f5d9af5e1b81db7168","壢中新聞":"WID_549_29_6b87c0e5ed0f8ecb2694390de5e69cc1d48ef84"},ATTR:{"全部":"","公告":"attr_1","通知":"attr_2","最新消息":"attr_3","緊急":"attr_4","校內競賽":"attr_5","校外競賽":"attr_6","獎助學金":"attr_7","榮譽榜":"attr_8","":"attr_9","研習營隊":"attr_10","衛生保健":"attr_11","升學資訊":"attr_12","法令公告":"attr_13"},UNIT:{"設備組官網":"unit_27","資訊媒體組":"unit_29","活動組官網":"unit_31","主計室官網":"unit_32","教學組官網":"unit_33","註冊組官網":"unit_34","試務組官網":"unit_35","訓育組官網":"unit_38","文書組":"unit_41","出納組":"unit_42","庶務組官網":"unit_43","人事室官網":"unit_44","教務處官網":"unit_50","學務處官網":"unit_53","學務處官網_duplicated1":"unit_54","舊輔導室官網":"unit_55","學務處官網_duplicated2":"unit_56","特教組官網":"unit_57","衛生組官網":"unit_61","生輔組官網":"unit_62","秘書室官網":"unit_63","中壢中學校友會":"unit_64","學務處官網_duplicated3":"unit_65","學務處官網_duplicated4":"unit_66","學務處官網_duplicated5":"unit_67","學務處官網_duplicated6":"unit_68","總務處官網":"unit_69","總務處官網_duplicated_1":"unit_70","總務處官網_duplicated_2":"unit_71","健康中心官網":"unit_75","家長會官網":"unit_79","教師甄選":"unit_91","輔導室官網":"unit_104","生輔組-防制學生藥物濫用":"unit_117","總務處官網_duplicated":"unit_137","十二年國教":"unit_140","翻轉與突破優質化計畫":"unit_153","校園食品安全專區":"unit_154","學習中心":"unit_155","新生專區":"unit_156","圖書館官網":"unit_399","壢崗文教基金會":"unit_403","athletic meet":"unit_405","自主學習":"unit_409","108選課輔導手冊":"unit_413","108年專業群科評鑑":"unit_414","110教師甄試網站":"unit_422","教師甄選成績查詢":"unit_423","109選課輔導手冊":"unit_424","中大壢中新首頁":"unit_425","數理資優班":"unit_430"}},f=function(){var t=i(u.mark((function t(r){var n,o;return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.get(c(r));case 2:if("Invalid nid!"!==(n=t.sent.data)){t.next=6;break}throw r+" is an invalid news id.";case 6:if(o=n.match(/var g_news_unique_id = "(\w+)"/)){t.next=9;break}throw"cannot find an uid for news id:"+r;case 9:return t.abrupt("return",o[1]);case 10:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),h=function(){var t=i(u.mark((function t(n){var o,i,a,s;return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,f(n);case 3:o=t.sent,t.next=9;break;case 6:return t.prev=6,t.t0=t.catch(0),t.abrupt("return",r.err({error:t.t0}));case 9:return t.next=11,e.get(c(n,o));case 11:if(a=(i=t.sent.data)[0],i.slice(1),a){t.next=17;break}return t.abrupt("return",r.err({error:"there's no data in the response object."}));case 17:s=a.content,t.prev=18,a.content=s?decodeURIComponent(s):s,t.next=25;break;case 22:return t.prev=22,t.t1=t.catch(18),t.abrupt("return",r.ok({data:a,warn:"error occurred while decoding the content."}));case 25:return t.abrupt("return",r.ok({data:a}));case 26:case"end":return t.stop()}}),t,null,[[0,6],[18,22]])})));return function(e){return t.apply(this,arguments)}}(),l=function(t){var e,r,n,o,i=t.where;return{auth_type:"user",field:"time",flock:(e=t.attr,r=t.unit,n=e?s.ATTR[e]:null,o=r?s.UNIT[r]:null,(o||"")+(o&&n?"-":"")+(n||"")||null),keyword:t.keyword||"",maxRows:t.itemsPerPage||20,order:t.orderBy||"DESC",pageNum:t.page||0,tf:1,uid:i?s.UID[i]:s.UID.首頁,use_cache:t.useCache?1:0}},d=function(){var t=i(u.mark((function t(o){var i,a,c,s;return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=l(o||{}),t.next=3,e.post("https://www.clhs.tyc.edu.tw/ischool/widget/site_news/news_query_json.php",new n.URLSearchParams(i).toString(),{headers:{"Content-type":"application/x-www-form-urlencoded; charset=UTF-8"}});case 3:if("string"!=typeof(a=t.sent.data)){t.next=7;break}return t.abrupt("return",r.err({error:"error from clhs api(might be wrong input type). error message: "+a}));case 7:if(c=a[0],s=a.slice(1),c.params=i,s.length){t.next=11;break}return t.abrupt("return",r.err({error:"no news can be found."}));case 11:return t.abrupt("return",r.ok({data:{queryMeta:c,newsList:s}}));case 12:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();exports.Options=s,exports.newsContentQuery=h,exports.newsListQuery=d; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=(t=require("axios"))&&"object"==typeof t&&"default"in t?t.default:t,r=require("url");function n(t,e,r,n,i,o,a){try{var u=t[o](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,i)}function i(t){return function(){var e=this,r=arguments;return new Promise((function(i,o){var a=t.apply(e,r);function u(t){n(a,i,o,u,c,"next",t)}function c(t){n(a,i,o,u,c,"throw",t)}u(void 0)}))}}function o(t,e){return t(e={exports:{}},e.exports),e.exports}var a=o((function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var i=Object.create((e&&e.prototype instanceof h?e:h).prototype),o=new L(n||[]);return i._invoke=function(t,e,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var u=m(a,r);if(u){if(u===f)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=s(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(t,r,o),i}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var f={};function h(){}function l(){}function d(){}var p={};u(p,i,(function(){return this}));var _=Object.getPrototypeOf,v=_&&_(_(E([])));v&&v!==e&&r.call(v,i)&&(p=v);var y=d.prototype=h.prototype=Object.create(p);function w(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function g(t,e){var n;this._invoke=function(i,o){function a(){return new e((function(n,a){!function n(i,o,a,u){var c=s(t[i],t,o);if("throw"!==c.type){var f=c.arg,h=f.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):e.resolve(h).then((function(t){f.value=t,a(f)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}(i,o,n,a)}))}return n=n?n.then(a,a):a()}}function m(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,m(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var i=n.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function b(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function E(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:k}}function k(){return{value:void 0,done:!0}}return l.prototype=d,u(y,"constructor",d),u(d,"constructor",l),l.displayName=u(d,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,a,"GeneratorFunction")),t.prototype=Object.create(y),t},t.awrap=function(t){return{__await:t}},w(g.prototype),u(g.prototype,o,(function(){return this})),t.AsyncIterator=g,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new g(c(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(y),u(y,a,"Generator"),u(y,i,(function(){return this})),u(y,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=E,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var u=r.call(o,"catchLoc"),c=r.call(o,"finallyLoc");if(u&&c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),x(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;x(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:E(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}})),u=function(t,e){return e?"https://www.clhs.tyc.edu.tw/ischool/widget/site_news/news_query_json_content.php?nid="+t+"&dir=0&uid="+e:"https://www.clhs.tyc.edu.tw/ischool/public/news_view/show.php?nid="+t},c={UID:{"首頁":"WID_549_2_3e2e399a2649fb6ba9918090490f4741fd4453bf","升學資訊":"WID_549_2_13cfc702096566ef38571aebe89498c49f56f236","法令公告":"WID_549_2_09b16f4944d742185cf599bb45ca292da6547c9e","校內競賽":"WID_549_2_c0df1de1135dbf425a0f988515224a49c98ad257","校外競賽":"WID_549_2_5d8f79c34d01e52061f469da52357fe253c45db9","新生專區":"WID_284_2_74ade31d9f46e4440ca9b60301b5f651004cec49","衛生保健":"WID_549_2_5cd5617d2dd2bc130e7f76c333f2d442dffd0681","營隊研習":"WID_549_2_0470a8e2b5755791156cb8f5d9af5e1b81db7168","壢中新聞":"WID_549_29_6b87c0e5ed0f8ecb2694390de5e69cc1d48ef84"},ATTR:{"全部":"","公告":"attr_1","通知":"attr_2","最新消息":"attr_3","緊急":"attr_4","校內競賽":"attr_5","校外競賽":"attr_6","獎助學金":"attr_7","榮譽榜":"attr_8","":"attr_9","研習營隊":"attr_10","衛生保健":"attr_11","升學資訊":"attr_12","法令公告":"attr_13"},UNIT:{"設備組官網":"unit_27","資訊媒體組":"unit_29","活動組官網":"unit_31","主計室官網":"unit_32","教學組官網":"unit_33","註冊組官網":"unit_34","試務組官網":"unit_35","訓育組官網":"unit_38","文書組":"unit_41","出納組":"unit_42","庶務組官網":"unit_43","人事室官網":"unit_44","教務處官網":"unit_50","學務處官網":"unit_53","學務處官網_duplicated1":"unit_54","舊輔導室官網":"unit_55","學務處官網_duplicated2":"unit_56","特教組官網":"unit_57","衛生組官網":"unit_61","生輔組官網":"unit_62","秘書室官網":"unit_63","中壢中學校友會":"unit_64","學務處官網_duplicated3":"unit_65","學務處官網_duplicated4":"unit_66","學務處官網_duplicated5":"unit_67","學務處官網_duplicated6":"unit_68","總務處官網":"unit_69","總務處官網_duplicated_1":"unit_70","總務處官網_duplicated_2":"unit_71","健康中心官網":"unit_75","家長會官網":"unit_79","教師甄選":"unit_91","輔導室官網":"unit_104","生輔組-防制學生藥物濫用":"unit_117","總務處官網_duplicated":"unit_137","十二年國教":"unit_140","翻轉與突破優質化計畫":"unit_153","校園食品安全專區":"unit_154","學習中心":"unit_155","新生專區":"unit_156","圖書館官網":"unit_399","壢崗文教基金會":"unit_403","athletic meet":"unit_405","自主學習":"unit_409","108選課輔導手冊":"unit_413","108年專業群科評鑑":"unit_414","110教師甄試網站":"unit_422","教師甄選成績查詢":"unit_423","109選課輔導手冊":"unit_424","中大壢中新首頁":"unit_425","數理資優班":"unit_430"}},s=function(){var t=i(a.mark((function t(r){var n,i;return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.get(u(r));case 2:if("Invalid nid!"!==(n=t.sent.data)){t.next=6;break}throw r+" is an invalid news id.";case 6:if(i=n.match(/var g_news_unique_id = "(\w+)"/)){t.next=9;break}throw"cannot find an uid for news id:"+r;case 9:return t.abrupt("return",i[1]);case 10:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),f=function(){var t=i(a.mark((function t(r,n){var i,o,c,f;return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,s(r);case 3:i=t.sent,t.next=9;break;case 6:return t.prev=6,t.t0=t.catch(0),t.abrupt("return",n({},t.t0));case 9:return t.next=11,e.get(u(r,i));case 11:if(c=(o=t.sent.data)[0],o.slice(1),c){t.next=17;break}return t.abrupt("return",n({},"there's no data in the response object."));case 17:f=c.content;try{c.content=f?decodeURIComponent(f):f}catch(t){}return t.abrupt("return",n(c));case 20:case"end":return t.stop()}}),t,null,[[0,6]])})));return function(e,r){return t.apply(this,arguments)}}(),h=function(t){var e,r,n,i,o=t.where;return{auth_type:"user",field:"time",flock:(e=t.attr,r=t.unit,n=e?c.ATTR[e]:null,i=r?c.UNIT[r]:null,(i||"")+(i&&n?"-":"")+(n||"")||null),keyword:t.keyword||"",maxRows:t.itemsPerPage||20,order:t.orderBy||"DESC",pageNum:t.page||0,tf:1,uid:o?c.UID[o]:c.UID.首頁,use_cache:t.useCache?1:0}},l=function(){var t=i(a.mark((function t(n,i){var o,u,c,s;return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=h(n||{}),t.next=3,e.post("https://www.clhs.tyc.edu.tw/ischool/widget/site_news/news_query_json.php",new r.URLSearchParams(o).toString(),{headers:{"Content-type":"application/x-www-form-urlencoded; charset=UTF-8"}});case 3:if("string"!=typeof(u=t.sent.data)){t.next=7;break}return t.abrupt("return",i({},"error from clhs api(might be wrong input type). error message: "+u));case 7:if(c=u[0],s=u.slice(1),c.params=o,s.length){t.next=11;break}return t.abrupt("return",i({},"no news can be found."));case 11:return t.abrupt("return",i({queryMeta:c,newsList:s}));case 12:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}();exports.Options=c,exports.newsContentQuery=f,exports.newsListQuery=l; | ||
//# sourceMappingURL=core.cjs.production.min.js.map |
import axios from 'axios'; | ||
import { ok, err } from 'neverthrow'; | ||
import { URLSearchParams } from 'url'; | ||
@@ -917,3 +916,3 @@ | ||
var newsContentQuery = /*#__PURE__*/function () { | ||
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(id) { | ||
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(id, cb) { | ||
var uid, _yield$axios$get, _yield$axios$get$data, data, _, content; | ||
@@ -937,5 +936,3 @@ | ||
_context.t0 = _context["catch"](0); | ||
return _context.abrupt("return", err({ | ||
error: _context.t0 | ||
})); | ||
return _context.abrupt("return", cb({}, _context.t0)); | ||
@@ -957,27 +954,15 @@ case 9: | ||
return _context.abrupt("return", err({ | ||
error: "there's no data in the response object." | ||
})); | ||
return _context.abrupt("return", cb({}, "there's no data in the response object.")); | ||
case 17: | ||
content = data.content; | ||
_context.prev = 18; | ||
data.content = !!!content ? content : decodeURIComponent(content); | ||
_context.next = 25; | ||
break; | ||
case 22: | ||
_context.prev = 22; | ||
_context.t1 = _context["catch"](18); | ||
return _context.abrupt("return", ok({ | ||
data: data, | ||
warn: "error occurred while decoding the content." | ||
})); | ||
try { | ||
data.content = !!!content ? content : decodeURIComponent(content); | ||
} catch (e) {// unable to decode some of the content, ignore this for now. | ||
} | ||
case 25: | ||
return _context.abrupt("return", ok({ | ||
data: data | ||
})); | ||
return _context.abrupt("return", cb(data)); | ||
case 26: | ||
case 20: | ||
case "end": | ||
@@ -987,6 +972,6 @@ return _context.stop(); | ||
} | ||
}, _callee, null, [[0, 6], [18, 22]]); | ||
}, _callee, null, [[0, 6]]); | ||
})); | ||
return function newsContentQuery(_x) { | ||
return function newsContentQuery(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
@@ -1027,3 +1012,3 @@ }; | ||
var newsListQuery = /*#__PURE__*/function () { | ||
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(queryInput) { | ||
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(queryInput, cb) { | ||
var params, _yield$axios$post, queryResult, queryMeta, newsList; | ||
@@ -1053,5 +1038,3 @@ | ||
return _context.abrupt("return", err({ | ||
error: "error from clhs api(might be wrong input type). error message: " + queryResult | ||
})); | ||
return _context.abrupt("return", cb({}, "error from clhs api(might be wrong input type). error message: " + queryResult)); | ||
@@ -1067,12 +1050,8 @@ case 7: | ||
return _context.abrupt("return", err({ | ||
error: "no news can be found." | ||
})); | ||
return _context.abrupt("return", cb({}, "no news can be found.")); | ||
case 11: | ||
return _context.abrupt("return", ok({ | ||
data: { | ||
queryMeta: queryMeta, | ||
newsList: newsList | ||
} | ||
return _context.abrupt("return", cb({ | ||
queryMeta: queryMeta, | ||
newsList: newsList | ||
})); | ||
@@ -1088,3 +1067,3 @@ | ||
return function newsListQuery(_x) { | ||
return function newsListQuery(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
@@ -1091,0 +1070,0 @@ }; |
@@ -1,8 +0,2 @@ | ||
import { Result } from "neverthrow"; | ||
import { NewsContent } from "../types"; | ||
export declare const newsContentQuery: (id: string) => Promise<Result<{ | ||
data: NewsContent; | ||
warn?: string | undefined; | ||
}, { | ||
error: string; | ||
}>>; | ||
export declare const newsContentQuery: (id: string, cb: (data: NewsContent, error?: string | undefined) => void) => Promise<void>; |
@@ -1,20 +0,6 @@ | ||
import { Result } from "neverthrow"; | ||
import { News } from "../types"; | ||
import { QueryResultMeta } from "./types"; | ||
export declare const newsListQuery: (queryInput?: Partial<{ | ||
attr: "" | "全部" | "公告" | "通知" | "最新消息" | "緊急" | "校內競賽" | "校外競賽" | "獎助學金" | "榮譽榜" | "研習營隊" | "衛生保健" | "升學資訊" | "法令公告"; | ||
itemsPerPage: number; | ||
keyword: string; | ||
orderBy: "DESC" | "ASC"; | ||
page: number; | ||
unit: "設備組官網" | "資訊媒體組" | "活動組官網" | "主計室官網" | "教學組官網" | "註冊組官網" | "試務組官網" | "訓育組官網" | "文書組" | "出納組" | "庶務組官網" | "人事室官網" | "教務處官網" | "學務處官網" | "學務處官網_duplicated1" | "舊輔導室官網" | "學務處官網_duplicated2" | "特教組官網" | "衛生組官網" | "生輔組官網" | "秘書室官網" | "中壢中學校友會" | "學務處官網_duplicated3" | "學務處官網_duplicated4" | "學務處官網_duplicated5" | "學務處官網_duplicated6" | "總務處官網" | "總務處官網_duplicated_1" | "總務處官網_duplicated_2" | "健康中心官網" | "家長會官網" | "教師甄選" | "輔導室官網" | "生輔組-防制學生藥物濫用" | "總務處官網_duplicated" | "十二年國教" | "翻轉與突破優質化計畫" | "校園食品安全專區" | "學習中心" | "新生專區" | "圖書館官網" | "壢崗文教基金會" | "athletic meet" | "自主學習" | "108選課輔導手冊" | "108年專業群科評鑑" | "110教師甄試網站" | "教師甄選成績查詢" | "109選課輔導手冊" | "中大壢中新首頁" | "數理資優班"; | ||
useCache: boolean; | ||
where: "校內競賽" | "校外競賽" | "衛生保健" | "升學資訊" | "法令公告" | "新生專區" | "首頁" | "營隊研習" | "壢中新聞"; | ||
}> | undefined) => Promise<Result<{ | ||
data: { | ||
queryMeta: QueryResultMeta; | ||
newsList: News[]; | ||
}; | ||
}, { | ||
error: string; | ||
}>>; | ||
import { QueryInput, QueryResultMeta } from "./types"; | ||
export declare const newsListQuery: (queryInput: QueryInput, cb: (data: { | ||
queryMeta: QueryResultMeta; | ||
newsList: News[]; | ||
}, error?: string | undefined) => void) => Promise<void>; |
@@ -10,3 +10,3 @@ { | ||
"typings": "dist/index.d.ts", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"bugs": { | ||
@@ -17,4 +17,2 @@ "url": "https://github.com/BWsix/CLHS-api.git/issues" | ||
"axios": "^0.24.0", | ||
"cheerio": "^1.0.0-rc.10", | ||
"neverthrow": "^4.3.0", | ||
"utility-types": "^3.10.0" | ||
@@ -21,0 +19,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2
263866
2053
- Removedcheerio@^1.0.0-rc.10
- Removedneverthrow@^4.3.0
- Removedboolbase@1.0.0(transitive)
- Removedcheerio@1.0.0(transitive)
- Removedcheerio-select@2.1.0(transitive)
- Removedcss-select@5.1.0(transitive)
- Removedcss-what@6.1.0(transitive)
- Removeddom-serializer@2.0.0(transitive)
- Removeddomelementtype@2.3.0(transitive)
- Removeddomhandler@5.0.3(transitive)
- Removeddomutils@3.2.2(transitive)
- Removedencoding-sniffer@0.2.0(transitive)
- Removedentities@4.5.0(transitive)
- Removedhtmlparser2@9.1.0(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedneverthrow@4.4.2(transitive)
- Removednth-check@2.1.1(transitive)
- Removedparse5@7.2.1(transitive)
- Removedparse5-htmlparser2-tree-adapter@7.1.0(transitive)
- Removedparse5-parser-stream@7.1.2(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedundici@6.21.1(transitive)
- Removedwhatwg-encoding@3.1.1(transitive)
- Removedwhatwg-mimetype@4.0.0(transitive)