File size: 2,062 Bytes
61d39e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Batch and Symlinks

2024-10-08

### Batch and Symlinks

All filesystem operations will eventually be available through batch requests.
Since batch requests can also handle the cases for single files, it seems silly
to support those endpoints too, so eventually most calls will be done through
`/batch`. Puter's legacy filesystem endpoints will always be supported, but a
future `api.___/fs/v2.0` urlspace for the filesystem API might not include them.

This is batch:

```javascript

await (async () => {

    const endpoint = 'http://api.puter.localhost:4100/batch';



    const ops = [ 

      {

        op: 'mkdir',

        path: '/default_user/Desktop/some-dir',

      },

      {

        op: 'write',

        path: '/default_user/Desktop/some-file.txt',

      }

    ];



    const blob = new Blob(["12345678"], { type: 'text/plain' });

    const formData = new FormData();

    for ( const op of ops ) {

      formData.append('operation', JSON.stringify(op));

    }

    formData.append('fileinfo', JSON.stringify({

        name: 'file.txt',

        size: 8,

        mime: 'text/plain',

    }));

    formData.append('file', blob, 'hello.txt');



    const response = await fetch(endpoint, {

        method: 'POST',

        headers: { 'Authorization': `Bearer ${puter.authToken}` },

        body: formData

    });

    return await response.json();

})();

```
Symlinks are also created via `/batch`

```javascript

await (async () => {

    const endpoint = 'http://api.puter.localhost:4100/batch';



    const ops = [ 

      {

        op: 'symlink',

        path: '~/Desktop',

        name: 'link',

        target: '/bb/Desktop/some'

      },

    ];



    const formData = new FormData();

    for ( const op of ops ) {

      formData.append('operation', JSON.stringify(op));

    }



    const response = await fetch(endpoint, {

        method: 'POST',

        headers: { 'Authorization': `Bearer ${puter.authToken}` },

        body: formData

    });

    return await response.json();

})();

```