forked from swift502/Sketchbook
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest3.ts
More file actions
125 lines (117 loc) · 4.16 KB
/
test3.ts
File metadata and controls
125 lines (117 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import git from 'isomorphic-git';
import * as fs from 'fs';
import { PromiseFsClient } from 'isomorphic-git';
const fsWrapper: PromiseFsClient = {
promises: {
readFile: async (path, options) => {
if (!path) return;
try {
const response = await fetch("http://localhost:8080/"+path);
if (!response.ok) throw new Error('Error reading file');
if (options && options.encoding === 'utf8') {
let a = await response.text();
return a;
} else {
return new Uint8Array(await response.arrayBuffer());
}
} catch (error) {
console.error('Error reading file:', error);
throw error;
}
},
writeFile: async (file, data, options) => {
const response = await fetch(`/api/fs/writeFile`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ file, data, options })
});
if (!response.ok) throw new Error('Error writing file');
},
unlink: async (path) => {
const response = await fetch(`/api/fs/unlink`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path })
});
if (!response.ok) throw new Error('Error deleting file');
},
readdir: async (path, options) => {
const response = await fetch(`/api/fs/readdir`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path, options })
});
if (!response.ok) throw new Error('Error reading directory');
return await response.json();
},
mkdir: async (path, options) => {
const response = await fetch(`/api/fs/mkdir`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path, options })
});
if (!response.ok) throw new Error('Error creating directory');
},
rmdir: async (path) => {
const response = await fetch(`/api/fs/rmdir`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path })
});
if (!response.ok) throw new Error('Error removing directory');
},
stat: async (path) => {
const response = await fetch(`/api/fs/stat`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path })
});
if (!response.ok) throw new Error('Error getting file stats');
return await response.json();
},
lstat: async (path) => {
const response = await fetch(`/api/fs/lstat`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path })
});
if (!response.ok) throw new Error('Error getting symbolic link stats');
return await response.json();
},
readlink: async (path, options) => {
const response = await fetch(`/api/fs/readlink`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path, options })
});
if (!response.ok) throw new Error('Error reading link');
return await response.json();
},
symlink: async (target, path, type) => {
const response = await fetch(`/api/fs/symlink`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ target, path, type })
});
if (!response.ok) throw new Error('Error creating symlink');
},
chmod: async (path, mode) => {
const response = await fetch(`/api/fs/chmod`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path, mode })
});
if (!response.ok) throw new Error('Error changing file permissions');
}
}
};
(async () => {
const commits = await git.log({
fs: fsWrapper,
dir: './',
depth: 10, // Adjust depth for more commits
});
commits.forEach(commit => {
console.log(commit);
});
})();