tangled
alpha
login
or
join now
moth11.net
/
rvcx
3
fork
atom
backend for xcvr appview
3
fork
atom
overview
issues
4
pulls
pipelines
refactor caching
moth11.net
5 months ago
d77aabed
2fdff4a4
+32
-23
2 changed files
expand all
collapse all
unified
split
server
internal
handler
lrcHandlers.go
recordmanager
media.go
+3
-23
server/internal/handler/lrcHandlers.go
···
247
247
if cid == "" {
248
248
h.serverError(w, errors.New("empty cid"))
249
249
}
250
250
-
uploadDir := "./uploads"
251
251
-
_, err = os.Stat(uploadDir)
252
252
-
if os.IsNotExist(err) {
253
253
-
os.Mkdir(uploadDir, 0755)
254
254
-
}
255
255
-
256
256
-
imgPath := fmt.Sprintf("%s/%s%s", uploadDir, did, cid)
257
257
-
_, err = os.Stat(imgPath)
250
250
+
imgPath, err := h.rm.AddImageToCache(did, cid, r.Context())
258
251
if err != nil {
259
259
-
blob, err := atputils.SyncGetBlob(did, cid, r.Context())
260
260
-
if err != nil {
261
261
-
h.serverError(w, err)
262
262
-
return
263
263
-
}
264
264
-
file, err := os.Create(imgPath)
265
265
-
if err != nil {
266
266
-
h.serverError(w, err)
267
267
-
return
268
268
-
}
269
269
-
_, err = file.Write(blob)
270
270
-
if err != nil {
271
271
-
h.serverError(w, err)
272
272
-
return
273
273
-
}
252
252
+
h.serverError(w, errors.New("beep: "+err.Error()))
253
253
+
return
274
254
}
275
255
276
256
stats, err := os.Stat(imgPath)
+29
server/internal/recordmanager/media.go
···
3
3
import (
4
4
"context"
5
5
"errors"
6
6
+
"fmt"
6
7
atoauth "github.com/bluesky-social/indigo/atproto/auth/oauth"
7
8
"github.com/bluesky-social/indigo/atproto/syntax"
8
9
lexutil "github.com/bluesky-social/indigo/lex/util"
9
10
"mime/multipart"
11
11
+
"os"
12
12
+
"rvcx/internal/atputils"
10
13
"rvcx/internal/lex"
11
14
"rvcx/internal/oauth"
12
15
"rvcx/internal/types"
···
15
18
16
19
func (rm *RecordManager) PostImage(cs *atoauth.ClientSession, file multipart.File, fileHeader *multipart.FileHeader, ctx context.Context) (*lexutil.BlobSchema, error) {
17
20
return oauth.UploadBLOB(cs, file, fileHeader, ctx)
21
21
+
}
22
22
+
23
23
+
func (rm *RecordManager) AddImageToCache(did string, cid string, ctx context.Context) (string, error) {
24
24
+
uploadDir := "./uploads"
25
25
+
_, err := os.Stat(uploadDir)
26
26
+
if os.IsNotExist(err) {
27
27
+
os.Mkdir(uploadDir, 0755)
28
28
+
}
29
29
+
30
30
+
imgPath := fmt.Sprintf("%s/%s%s", uploadDir, did, cid)
31
31
+
_, err = os.Stat(imgPath)
32
32
+
if err != nil {
33
33
+
blob, err := atputils.SyncGetBlob(did, cid, ctx)
34
34
+
if err != nil {
35
35
+
return "", err
36
36
+
}
37
37
+
file, err := os.Create(imgPath)
38
38
+
if err != nil {
39
39
+
return "", err
40
40
+
}
41
41
+
_, err = file.Write(blob)
42
42
+
if err != nil {
43
43
+
return "", err
44
44
+
}
45
45
+
}
46
46
+
return imgPath, nil
18
47
}
19
48
20
49
func (rm *RecordManager) PostMedia(cs *atoauth.ClientSession, mr *types.ParseMediaRequest, ctx context.Context) error {