Skip to content

Commit 2c51157

Browse files
committed
Update gitapi.js
1 parent 63df6cd commit 2c51157

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

git/gitapi.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,39 @@ let git = {
150150

151151
return buffer;
152152

153+
},
154+
155+
// get public LFS file content as ReadableStream
156+
'getPublicLFSFileAsStream': async (treeLoc, fileName) => {
157+
158+
// map tree location
159+
let query = 'https://media.githubusercontent.com/media';
160+
const [user, repo, contents] = treeLoc;
161+
162+
// get repository branch
163+
let [repoName, branch] = repo.split(':');
164+
165+
query += '/' + user + '/' + repoName +
166+
'/' + branch +
167+
'/' + contents + '/' + fileName;
168+
169+
// get the query
170+
const resp = await fetch(query);
171+
172+
// if received an error
173+
if (String(resp.status).startsWith('4')) {
174+
175+
return {
176+
errorCode: resp.status
177+
};
178+
179+
}
180+
181+
182+
const buffer = await resp.arrayBuffer();
183+
184+
return buffer;
185+
153186
},
154187

155188
// get items in tree
@@ -184,7 +217,7 @@ let git = {
184217
return resp;
185218

186219
},
187-
220+
188221
// get a repository
189222
'getRepo': async (treeLoc) => {
190223

0 commit comments

Comments
 (0)