jobscraper/server/dist/build/bundle.js
Martin Donnelly 93137e1ee5 * Added auth
* Added sql rebuild
* Moved dist to be under server
2020-05-26 12:57:11 +01:00

2 lines
14 KiB
JavaScript

var app=function(){"use strict";function t(){}function e(t){return t()}function n(){return Object.create(null)}function r(t){t.forEach(e)}function o(t){return"function"==typeof t}function a(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function s(e,n,r){e.$$.on_destroy.push(function(e,...n){if(null==e)return t;const r=e.subscribe(...n);return r.unsubscribe?()=>r.unsubscribe():r}(n,r))}function c(t,e){t.appendChild(e)}function i(t,e,n){t.insertBefore(e,n||null)}function l(t){t.parentNode.removeChild(t)}function u(t){return document.createElement(t)}function d(t){return document.createTextNode(t)}function f(){return d(" ")}function p(t,e,n,r){return t.addEventListener(e,n,r),()=>t.removeEventListener(e,n,r)}function h(t,e,n){null==n?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function m(t,e){e=""+e,t.data!==e&&(t.data=e)}let g;function b(t){g=t}const y=[],v=[],$=[],x=[],w=Promise.resolve();let k=!1;function J(t){$.push(t)}let _=!1;const A=new Set;function C(){if(!_){_=!0;do{for(let t=0;t<y.length;t+=1){const e=y[t];b(e),j(e.$$)}for(y.length=0;v.length;)v.pop()();for(let t=0;t<$.length;t+=1){const e=$[t];A.has(e)||(A.add(e),e())}$.length=0}while(y.length);for(;x.length;)x.pop()();k=!1,_=!1,A.clear()}}function j(t){if(null!==t.fragment){t.update(),r(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(J)}}const L=new Set;function S(t,e){t&&t.i&&(L.delete(t),t.i(e))}function T(t,e,n,r){if(t&&t.o){if(L.has(t))return;L.add(t),(void 0).c.push(()=>{L.delete(t),r&&(n&&t.d(1),r())}),t.o(e)}}function M(t){t&&t.c()}function N(t,n,a){const{fragment:s,on_mount:c,on_destroy:i,after_update:l}=t.$$;s&&s.m(n,a),J(()=>{const n=c.map(e).filter(o);i?i.push(...n):r(n),t.$$.on_mount=[]}),l.forEach(J)}function O(t,e){const n=t.$$;null!==n.fragment&&(r(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function R(t,e){-1===t.$$.dirty[0]&&(y.push(t),k||(k=!0,w.then(C)),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function E(e,o,a,s,c,i,u=[-1]){const d=g;b(e);const f=o.props||{},p=e.$$={fragment:null,ctx:null,props:i,update:t,not_equal:c,bound:n(),on_mount:[],on_destroy:[],before_update:[],after_update:[],context:new Map(d?d.$$.context:[]),callbacks:n(),dirty:u};let h=!1;if(p.ctx=a?a(e,f,(t,n,...r)=>{const o=r.length?r[0]:n;return p.ctx&&c(p.ctx[t],p.ctx[t]=o)&&(p.bound[t]&&p.bound[t](o),h&&R(e,t)),n}):[],p.update(),h=!0,r(p.before_update),p.fragment=!!s&&s(p.ctx),o.target){if(o.hydrate){const t=function(t){return Array.from(t.childNodes)}(o.target);p.fragment&&p.fragment.l(t),t.forEach(l)}else p.fragment&&p.fragment.c();o.intro&&S(e.$$.fragment),N(e,o.target,o.anchor),C()}b(d)}class D{$destroy(){O(this,1),this.$destroy=t}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}$set(){}}const q=[];function H(e,n=t){let r;const o=[];function s(t){if(a(e,t)&&(e=t,r)){const t=!q.length;for(let t=0;t<o.length;t+=1){const n=o[t];n[1](),q.push(n,e)}if(t){for(let t=0;t<q.length;t+=2)q[t][0](q[t+1]);q.length=0}}}return{set:s,update:function(t){s(t(e))},subscribe:function(a,c=t){const i=[a,c];return o.push(i),1===o.length&&(r=n(s)||t),a(e),()=>{const t=o.indexOf(i);-1!==t&&o.splice(t,1),0===o.length&&(r(),r=null)}}}}var P=function t(e){function n(t){return function(e,n){return a(e,Object.assign({method:t},n))}}function r(t){return function(e,n,r){return a(e,Object.assign({method:t,data:n},r))}}function o(t,e,n){if(Array.isArray(t))return t.concat(e);if(e&&"object"==typeof e){var r,a={};if(t)for(r in t)a[n?r.toLowerCase():r]=t[r];for(r in e){var s=n?r.toLowerCase():r;"headers"===s&&(n=!0),a[s]=r in a?o(a[s],e[r],n):e[r]}return a}return e}function a(t,n){"string"!=typeof t&&(t=(n=t).url);var r=o(e,n||{}),a=r.data;if(r.transformRequest)for(var s=0;s<r.transformRequest.length;s++){var c=r.transformRequest[s](a,r.headers);void 0!==c&&(a=c)}var i={};if(a&&"object"==typeof a&&(a=JSON.stringify(a),i["Content-Type"]="application/json"),r.xsrfCookieName)for(var l=document.cookie.split(/ *[;=] */),u=0;u<l.length;u+=2)if(l[u]==r.xsrfCookieName){i[r.xsrfHeaderName]=decodeURIComponent(l[u+1]);break}r.auth&&(i.Authorization=r.auth);var d={};return d.config=n,fetch(t,{method:r.method,body:a,headers:o(r.headers,i,!0)}).then((function(t){var e;for(e in t)"function"!=typeof t[e]&&(d[e]=t[e]);return(r.validateStatus?r.validateStatus(t.status):t.ok)?("stream"===r.responseType?Promise.resolve(t.body):t[r.responseType||"text"]()).then((function(t){return d.data=t,d})):Promise.reject(t)}))}return e=e||{},a.request=a,a.get=n("get"),a.delete=n("delete"),a.options=n("options"),a.post=r("post"),a.put=r("put"),a.patch=r("patch"),a.all=Promise.all,a.spread=function(t){return function(e){return t.apply(this,e)}},a.CancelToken=self.AbortController||Object,a.create=t,a}();const I=`${location.protocol}//${location.hostname}:3000`,z={jobs:I.concat("/jobs"),apply:I.concat("/apply"),readall:I.concat("/readall")},F=H([]),B=H({}),U={getJobList(){P.get(z.jobs).then(t=>{const e=JSON.parse(t.data);F.set(e)}).catch(t=>{console.error("getJobList",t)})},loadJobDetail(t){if(console.log("loadJobDetail: "+t),t){const e=`${z.jobs}/${t}`;P.get(e).then(t=>{const e=JSON.parse(t.data);B.set(e)}).catch(t=>{console.error("loadJobDetail",t)})}},async touchJob(t){if(console.log("touchJob: "+t),t){const e=`${z.jobs}/${t}`;await P.put(e).then(t=>{200!==t.status&&console.error(t)}).catch(t=>{console.error("touchJob",t)});const n=parseInt(t,10);F.update(t=>(t.map(t=>{if(t._id===n)return t.d=(new Date).getTime(),t}),t))}},async appliedJob(t){console.log("touchJob: "+t);const e=(new Date).getTime();if(t){console.log("Applying..");const n=`${z.apply}/${t}`;await P.put(n).then(t=>{200!==t.status&&console.error(t)}).catch(t=>{console.error("appliedJob",t)});const r=parseInt(t,10);F.update(t=>(t.map(t=>{if(t._id===r)return t.a=e,t}),t)),B.update(t=>(t.a=e,t))}},async markAllRead(){console.log(">> markAllRead");const t=""+z.readall;await P.put(t).then(t=>{200!==t.status&&console.error(t)}).catch(t=>{console.error("markAllRead",t)}),this.getJobList()}};function W(t,e,n){const r=t.slice();return r[4]=e[n],r[6]=n,r}function G(t){let e,n,r,o,a,s,g,b,y,v,$,x,w,k,J,_,A=t[4].title+"",C=t[4].site+"",j=Q(t[4].company)+"",L=t[4].date+"";return{c(){e=u("tr"),n=u("td"),r=d(A),o=f(),a=u("td"),s=d(C),g=f(),b=u("td"),y=d(j),v=f(),$=u("td"),x=d(L),w=f(),h(e,"class",k="dataRow "+(t[4].d?"read":"")+" "+(t[4].a?"applied":"")+" svelte-bblkbk"),h(e,"data-id",J=t[4]._id)},m(l,u,d){var f;i(l,e,u),c(e,n),c(n,r),c(e,o),c(e,a),c(a,s),c(e,g),c(e,b),c(b,y),c(e,v),c(e,$),c($,x),c(e,w),d&&_(),_=p(e,"click",(f=t[1],function(t){return t.stopPropagation(),f.call(this,t)}))},p(t,n){1&n&&A!==(A=t[4].title+"")&&m(r,A),1&n&&C!==(C=t[4].site+"")&&m(s,C),1&n&&j!==(j=Q(t[4].company)+"")&&m(y,j),1&n&&L!==(L=t[4].date+"")&&m(x,L),1&n&&k!==(k="dataRow "+(t[4].d?"read":"")+" "+(t[4].a?"applied":"")+" svelte-bblkbk")&&h(e,"class",k),1&n&&J!==(J=t[4]._id)&&h(e,"data-id",J)},d(t){t&&l(e),_()}}}function K(e){let n,r,o,a,s,d=e[0],p=[];for(let t=0;t<d.length;t+=1)p[t]=G(W(e,d,t));return{c(){n=u("div"),r=u("table"),o=u("thead"),o.innerHTML='<tr><th class="col-5">\n Title\n </th> \n <th class="col-2">\n Site\n </th> \n <th class="col-3">\n Company\n </th> \n <th class="col-2">\n Date\n </th></tr>',a=f(),s=u("tbody");for(let t=0;t<p.length;t+=1)p[t].c();h(r,"class",""),h(n,"class","lister svelte-bblkbk")},m(t,e){i(t,n,e),c(n,r),c(r,o),c(r,a),c(r,s);for(let t=0;t<p.length;t+=1)p[t].m(s,null)},p(t,[e]){if(3&e){let n;for(d=t[0],n=0;n<d.length;n+=1){const r=W(t,d,n);p[n]?p[n].p(r,e):(p[n]=G(r),p[n].c(),p[n].m(s,null))}for(;n<p.length;n+=1)p[n].d(1);p.length=d.length}},i:t,o:t,d(t){t&&l(n),function(t,e){for(let n=0;n<t.length;n+=1)t[n]&&t[n].d(e)}(p,t)}}}function Q(t){return t.length<=40?t:t.slice(0,40)+"…"}function V(t,e,n){let r;return s(t,F,t=>n(0,r=t)),[r,function(t){const e=t.target.parentElement.dataset.id;U.loadJobDetail(e),U.touchJob(e)}]}class X extends D{constructor(t){super(),E(this,t,V,K,a,{})}}function Y(t){let e,n,r,o,a,s,p,g,b,y,v,$,x,w,k,J,_,A,C,j,L,S,T,M,N,O,R,E,D,q,H,P,I,z,F,B,U,W,G,K=t[2].title+"",Q=t[2].company+"",V=t[2].location+"",X=t[2].salary+"",Y=t[2].date+"",et=t[2].site+"",nt=t[2].summary+"";function rt(t,e){return t[2].a?Z:tt}let ot=rt(t),at=ot(t);return{c(){e=u("div"),n=u("div"),r=u("div"),o=u("div"),a=d(K),s=f(),p=u("div"),g=u("div"),b=d("Company: "),y=u("span"),v=d(Q),$=f(),x=u("div"),w=d("Location: "),k=u("span"),J=d(V),_=f(),A=u("div"),C=d("Applied:\n "),at.c(),j=f(),L=u("div"),S=u("div"),T=d("Salary: "),M=u("span"),N=d(X),O=f(),R=u("div"),E=d("Scraped: "),D=u("span"),q=d(Y),H=f(),P=u("div"),I=d("Site: "),z=u("a"),F=d(et),W=f(),G=u("blockquote"),h(o,"class","col-12 text-primary lead"),h(r,"class","row svelte-r7f80i"),h(y,"class","text-primary"),h(g,"class","col-1-3rd"),h(k,"class","text-primary"),h(x,"class","col-1-3rd"),h(A,"class","col-1-3rd"),h(p,"class","row svelte-r7f80i"),h(M,"class","text-primary"),h(S,"class","col-1-3rd"),h(D,"class","text-primary"),h(R,"class","col-1-3rd"),h(z,"href",B=t[2].url),h(z,"class","text-capitalize"),h(z,"target","_blank"),h(P,"class","col-1-3rd"),h(L,"class","row svelte-r7f80i"),h(n,"class",U="detailHead bg-light "+(t[1]?"applied":"")+" svelte-r7f80i"),h(e,"class","detail svelte-r7f80i")},m(t,l){i(t,e,l),c(e,n),c(n,r),c(r,o),c(o,a),c(n,s),c(n,p),c(p,g),c(g,b),c(g,y),c(y,v),c(p,$),c(p,x),c(x,w),c(x,k),c(k,J),c(p,_),c(p,A),c(A,C),at.m(A,null),c(n,j),c(n,L),c(L,S),c(S,T),c(S,M),c(M,N),c(L,O),c(L,R),c(R,E),c(R,D),c(D,q),c(L,H),c(L,P),c(P,I),c(P,z),c(z,F),c(e,W),c(e,G),G.innerHTML=nt},p(t,e){4&e&&K!==(K=t[2].title+"")&&m(a,K),4&e&&Q!==(Q=t[2].company+"")&&m(v,Q),4&e&&V!==(V=t[2].location+"")&&m(J,V),ot===(ot=rt(t))&&at?at.p(t,e):(at.d(1),at=ot(t),at&&(at.c(),at.m(A,null))),4&e&&X!==(X=t[2].salary+"")&&m(N,X),4&e&&Y!==(Y=t[2].date+"")&&m(q,Y),4&e&&et!==(et=t[2].site+"")&&m(F,et),4&e&&B!==(B=t[2].url)&&h(z,"href",B),2&e&&U!==(U="detailHead bg-light "+(t[1]?"applied":"")+" svelte-r7f80i")&&h(n,"class",U),4&e&&nt!==(nt=t[2].summary+"")&&(G.innerHTML=nt)},d(t){t&&l(e),at.d()}}}function Z(e){let n;return{c(){n=d("Applied!")},m(t,e){i(t,n,e)},p:t,d(t){t&&l(n)}}}function tt(e){let n,r;return{c(){n=u("button"),n.textContent="Applied",h(n,"class","btn btn-sm btn-primary")},m(t,o,a){i(t,n,o),a&&r(),r=p(n,"click",e[3])},p:t,d(t){t&&l(n),r()}}}function et(e){let n,r=e[0]&&Y(e);return{c(){r&&r.c(),n=d("")},m(t,e){r&&r.m(t,e),i(t,n,e)},p(t,[e]){t[0]?r?r.p(t,e):(r=Y(t),r.c(),r.m(n.parentNode,n)):r&&(r.d(1),r=null)},i:t,o:t,d(t){r&&r.d(t),t&&l(n)}}}function nt(t,e,n){let r;s(t,B,t=>n(2,r=t));let o,a=!1;return B.subscribe(t=>{n(0,a=!function(t){for(const e in t)if(t.hasOwnProperty(e))return!1;return!0}(t))}),t.$$.update=()=>{4&t.$$.dirty&&n(1,o="number"==typeof r.a)},[a,o,r,function(){U.appliedJob(r._id)}]}class rt extends D{constructor(t){super(),E(this,t,nt,et,a,{})}}function ot(e){let n,r,o,a,s,d,m;return{c(){n=u("header"),r=u("section"),o=u("span"),o.textContent=""+at,a=f(),s=u("section"),d=u("button"),d.textContent="Mark All Read",h(o,"class","text-bold navbar-brand mx-1 text-uppercase"),h(r,"class","navbar-section"),h(d,"class","btn btn-sm btn-primary"),h(s,"class","navbar-section text-right"),h(n,"class","navbar bg-primary")},m(t,l,u){i(t,n,l),c(n,r),c(r,o),c(n,a),c(n,s),c(s,d),u&&m(),m=p(d,"click",e[0])},p:t,i:t,o:t,d(t){t&&l(n),m()}}}let at="Jobs";function st(t){return[function(){U.markAllRead()}]}class ct extends D{constructor(t){super(),E(this,t,st,ot,a,{})}}function it(e){let n,r,o,a,s;const d=new ct({}),p=new X({}),m=new rt({});return{c(){M(d.$$.fragment),n=f(),r=u("div"),o=u("div"),M(p.$$.fragment),a=f(),M(m.$$.fragment),h(o,"class","col-12"),h(r,"class","container fullWidth")},m(t,e){N(d,t,e),i(t,n,e),i(t,r,e),c(r,o),N(p,o,null),c(o,a),N(m,o,null),s=!0},p:t,i(t){s||(S(d.$$.fragment,t),S(p.$$.fragment,t),S(m.$$.fragment,t),s=!0)},o(t){T(d.$$.fragment,t),T(p.$$.fragment,t),T(m.$$.fragment,t),s=!1},d(t){O(d,t),t&&l(n),t&&l(r),O(p),O(m)}}}var lt=1e3,ut=6e4,dt=60*ut,ft=24*dt,pt=function(t,e){e=e||{};var n=typeof t;if("string"===n&&t.length>0)return function(t){if((t=String(t)).length>100)return;var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(!e)return;var n=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*n;case"weeks":case"week":case"w":return 6048e5*n;case"days":case"day":case"d":return n*ft;case"hours":case"hour":case"hrs":case"hr":case"h":return n*dt;case"minutes":case"minute":case"mins":case"min":case"m":return n*ut;case"seconds":case"second":case"secs":case"sec":case"s":return n*lt;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}(t);if("number"===n&&isFinite(t))return e.long?function(t){var e=Math.abs(t);if(e>=ft)return ht(t,e,ft,"day");if(e>=dt)return ht(t,e,dt,"hour");if(e>=ut)return ht(t,e,ut,"minute");if(e>=lt)return ht(t,e,lt,"second");return t+" ms"}(t):function(t){var e=Math.abs(t);if(e>=ft)return Math.round(t/ft)+"d";if(e>=dt)return Math.round(t/dt)+"h";if(e>=ut)return Math.round(t/ut)+"m";if(e>=lt)return Math.round(t/lt)+"s";return t+"ms"}(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function ht(t,e,n,r){var o=e>=1.5*n;return Math.round(t/n)+" "+r+(o?"s":"")}let mt=0;const gt=new class extends D{constructor(t){super(),E(this,t,null,it,a,{})}}({target:document.body});return function t(){U.getJobList();const e=function(t=0){return 36e5-(new Date).getTime()%36e5+t}()+pt("10m");console.log("Next:",e),mt=setTimeout(()=>{t()},e)}(),gt}();