MCPcopy
hub / github.com/witheve/Eve / readFromGist

Function readFromGist

src/util.ts:209–230  ·  view source on GitHub ↗
(url:string, callback:(error:Error, content?:GistResponse) => void)

Source from the content-addressed store, hash-verified

207interface GistResponse {id: string, url: string, files: {[name:string]: {content: string}}}
208
209export function readFromGist(url:string, callback:(error:Error, content?:GistResponse) => void) {
210 let gistId = gistIdFromUrl(url);
211
212 if(!gistId) return callback(new Error(`Invalid gist url: '${url}'.`));
213
214 let apiUrl = `https://api.github.com/gists/${gistId}`;
215
216 let request = new XMLHttpRequest();
217 request.onreadystatechange = function() {
218 if(request.readyState === 4) {
219 if(request.status !== 200) {
220 return callback(new Error(`HTTP Response: ${request.status}`));
221 }
222
223 let response = JSON.parse(request.responseText);
224
225 callback(undefined, response);
226 }
227 }
228 request.open("GET", apiUrl);
229 request.send();
230}

Callers 1

loadFromGistMethod · 0.90

Calls 2

gistIdFromUrlFunction · 0.85
sendMethod · 0.65

Tested by

no test coverage detected