-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathia.min.js
1 lines (1 loc) · 7.88 KB
/
ia.min.js
1
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.InternetArchive=e()}}(function(){var e;return function t(e,r,o){function n(a,s){if(!r[a]){if(!e[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(i)return i(a,!0);var d=new Error("Cannot find module '"+a+"'");throw d.code="MODULE_NOT_FOUND",d}var f=r[a]={exports:{}};e[a][0].call(f.exports,function(t){var r=e[a][1][t];return n(r?r:t)},f,f.exports,t,e,r,o)}return r[a].exports}for(var i="function"==typeof require&&require,a=0;a<o.length;a++)n(o[a]);return n}({1:[function(e,t,r){function o(e){var t={identifier:null,itemMetadata:null};void 0===e&&(e={}),e=Object.assign(t,e),this.identifier=e.identifier,this.exists=!1,this.metadata={},this.files=[],this.created=null,this.d1=null,this.d2=null,this.dir=null,this.files_count=null,this.item_size=null,this.reviews=[],this.server=null,this.uniq=null,this.updated=null,this.tasks=null,this.is_dark=null,this.load(e.itemMetadata)}t.exports=o,o.prototype.load=function(e){this.itemMetadata=e,Object.assign(this,this.itemMetadata),this.exists=this.itemMetadata!=={},this.identifier||(this.identifier=this.metadata.identifier)},o.prototype.saveMetadata=function(){throw Error("not implemented yet")},o.prototype.uploadFile=function(){throw Error("not implemented yet")},o.prototype.getFile=function(e){throw Error("not implemented yet")}},{}],2:[function(t,r,o){!function(t,n){"function"==typeof e&&e.amd?e([],n):"object"==typeof o?r.exports=n():t.returnExports=n()}(this,function(){function e(n,i){if("function"!=typeof i)throw new Error("Bad callback given: "+i);if(!n)throw new Error("No options given");var s=n.onResponse;if(n="string"==typeof n?{uri:n}:JSON.parse(JSON.stringify(n)),n.onResponse=s,n.verbose&&(e.log=o()),n.url&&(n.uri=n.url,delete n.url),!n.uri&&""!==n.uri)throw new Error("options.uri is a required argument");if("string"!=typeof n.uri)throw new Error("options.uri must be a string");for(var u=["proxy","_redirectsFollowed","maxRedirects","followRedirect"],d=0;d<u.length;d++)if(n[u[d]])throw new Error("options."+u[d]+" is not supported");if(n.callback=i,n.method=n.method||"GET",n.headers=n.headers||{},n.body=n.body||null,n.timeout=n.timeout||e.DEFAULT_TIMEOUT,n.headers.host)throw new Error("Options.headers.host is not supported");n.json&&(n.headers.accept=n.headers.accept||"application/json","GET"!==n.method&&(n.headers["content-type"]="application/json"),"boolean"!=typeof n.json?n.body=JSON.stringify(n.json):"string"!=typeof n.body&&(n.body=JSON.stringify(n.body)));var f=function(e){var t=[];for(var r in e)e.hasOwnProperty(r)&&t.push(encodeURIComponent(r)+"="+encodeURIComponent(e[r]));return t.join("&")};if(n.qs){var c="string"==typeof n.qs?n.qs:f(n.qs);-1!==n.uri.indexOf("?")?n.uri=n.uri+"&"+c:n.uri=n.uri+"?"+c}var l=function(e){var t={};t.boundry="-------------------------------"+Math.floor(1e9*Math.random());var r=[];for(var o in e)e.hasOwnProperty(o)&&r.push("--"+t.boundry+'\nContent-Disposition: form-data; name="'+o+'"\n\n'+e[o]+"\n");return r.push("--"+t.boundry+"--"),t.body=r.join(""),t.length=t.body.length,t.type="multipart/form-data; boundary="+t.boundry,t};if(n.form){if("string"==typeof n.form)throw"form name unsupported";if("POST"===n.method){var p=(n.encoding||"application/x-www-form-urlencoded").toLowerCase();switch(n.headers["content-type"]=p,p){case"application/x-www-form-urlencoded":n.body=f(n.form).replace(/%20/g,"+");break;case"multipart/form-data":var h=l(n.form);n.body=h.body,n.headers["content-type"]=h.type;break;default:throw new Error("unsupported encoding:"+p)}}}return n.onResponse=n.onResponse||r,n.onResponse===!0&&(n.onResponse=i,n.callback=r),!n.headers.authorization&&n.auth&&(n.headers.authorization="Basic "+a(n.auth.username+":"+n.auth.password)),t(n)}function t(t){function r(){c=!0;var r=new Error("ETIMEDOUT");return r.code="ETIMEDOUT",r.duration=t.timeout,e.log.error("Timeout",{id:f._id,milliseconds:t.timeout}),t.callback(r,f)}function o(r){if(c)return e.log.debug("Ignoring timed out state change",{state:f.readyState,id:f.id});if(e.log.debug("State change",{state:f.readyState,id:f.id,timed_out:c}),f.readyState===s.OPENED){e.log.debug("Request started",{id:f.id});for(var o in t.headers)f.setRequestHeader(o,t.headers[o])}else f.readyState===s.HEADERS_RECEIVED?n():f.readyState===s.LOADING?(n(),a()):f.readyState===s.DONE&&(n(),a(),u())}function n(){if(!y.response){if(y.response=!0,e.log.debug("Got response",{id:f.id,status:f.status}),clearTimeout(f.timeoutTimer),f.statusCode=f.status,l&&0==f.statusCode){var r=new Error("CORS request rejected: "+t.uri);return r.cors="rejected",y.loading=!0,y.end=!0,t.callback(r,f)}t.onResponse(null,f)}}function a(){y.loading||(y.loading=!0,e.log.debug("Response body loading",{id:f.id}))}function u(){if(!y.end){if(y.end=!0,e.log.debug("Request done",{id:f.id}),f.body=f.responseText,t.json)try{f.body=JSON.parse(f.responseText)}catch(r){return t.callback(r,f)}t.callback(null,f,f.body)}}var f=new s,c=!1,l=i(t.uri),p="withCredentials"in f;if(d+=1,f.seq_id=d,f.id=d+": "+t.method+" "+t.uri,f._id=f.id,l&&!p){var h=new Error("Browser does not support cross-origin request: "+t.uri);return h.cors="unsupported",t.callback(h,f)}f.timeoutTimer=setTimeout(r,t.timeout);var y={response:!1,loading:!1,end:!1};return f.onreadystatechange=o,f.open(t.method,t.uri,!0),l&&(f.withCredentials=!!t.withCredentials),f.send(t.body),f}function r(){}function o(){var e,t,o={},i=["trace","debug","info","warn","error"];for(t=0;t<i.length;t++)e=i[t],o[e]=r,"undefined"!=typeof console&&console&&console[e]&&(o[e]=n(console,e));return o}function n(e,t){function r(r,o){return"object"==typeof o&&(r+=" "+JSON.stringify(o)),e[t].call(e,r)}return r}function i(e){var t,r=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/;try{t=location.href}catch(o){t=document.createElement("a"),t.href="",t=t.href}var n=r.exec(t.toLowerCase())||[],i=r.exec(e.toLowerCase()),a=!(!i||i[1]==n[1]&&i[2]==n[2]&&(i[3]||("http:"===i[1]?80:443))==(n[3]||("http:"===n[1]?80:443)));return a}function a(e){var t,r,o,n,i,a,s,u,d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",f=0,c=0,l="",p=[];if(!e)return e;do t=e.charCodeAt(f++),r=e.charCodeAt(f++),o=e.charCodeAt(f++),u=t<<16|r<<8|o,n=u>>18&63,i=u>>12&63,a=u>>6&63,s=63&u,p[c++]=d.charAt(n)+d.charAt(i)+d.charAt(a)+d.charAt(s);while(f<e.length);switch(l=p.join(""),e.length%3){case 1:l=l.slice(0,-2)+"==";break;case 2:l=l.slice(0,-1)+"="}return l}var s=XMLHttpRequest;if(!s)throw new Error("missing XMLHttpRequest");e.log={trace:r,debug:r,info:r,warn:r,error:r};var u=18e4,d=0;e.withCredentials=!1,e.DEFAULT_TIMEOUT=u,e.defaults=function(t,r){var o=function(e){var r=function(r,o){r="string"==typeof r?{uri:r}:JSON.parse(JSON.stringify(r));for(var n in t)void 0===r[n]&&(r[n]=t[n]);return e(r,o)};return r},n=o(e);return n.get=o(e.get),n.post=o(e.post),n.put=o(e.put),n.head=o(e.head),n};var f=["get","put","post","head"];return f.forEach(function(t){var r=t.toUpperCase(),o=t.toLowerCase();e[o]=function(t){"string"==typeof t?t={method:r,uri:t}:(t=JSON.parse(JSON.stringify(t)),t.method=r);var o=[t].concat(Array.prototype.slice.apply(arguments,[1]));return e.apply(this,o)}}),e.couch=function(t,o){function n(e,t,r){if(e)return o(e,t,r);if((t.statusCode<200||t.statusCode>299)&&r.error){e=new Error("CouchDB error: "+(r.error.reason||r.error.error));for(var n in r)e[n]=r[n];return o(e,t,r)}return o(e,t,r)}"string"==typeof t&&(t={uri:t}),t.json=!0,t.body&&(t.json=t.body),delete t.body,o=o||r;var i=e(t,n);return i},e})},{}],3:[function(e,t,r){function o(e){}t.exports=o;var n=e("request"),i=e("./item.js");o.prototype.getItem=function(e,t){var r="https://archive.org/metadata/"+e+"&output=json";n(r,function(e,r){if(e)console.log("There was an error."),t(1,null);else{var o=new i({itemMetadata:JSON.parse(r.body)});t(null,o)}})}},{"./item.js":1,request:2}]},{},[3])(3)});