repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
9806086
parent
adf0961
author
Eric Bower
date
2023-08-16 18:20:58 +0000 UTC
chore: delete orphaned assets when linking projects
1 files changed,  +9, -25
M pgs/wish.go
+9, -25
 1@@ -236,36 +236,20 @@ func WishMiddleware(handler *uploadassets.UploadAssetHandler) wish.Middleware {
 2 					return
 3 				}
 4 
 5-				/* bucketName := shared.GetAssetBucketName(user.ID)
 6-				bucket, err := store.GetBucket(bucketName)
 7-				if err != nil {
 8-					log.Error(err)
 9-					utils.ErrorHandler(session, err)
10-					return
11-				}
12+				out := fmt.Sprintf("(%s) might have orphaned assets, removing ...\n", projectName)
13+				_, _ = session.Write([]byte(out))
14 
15-				fileList, err := store.ListFiles(bucket, projectName+"/", true)
16+				pd := ProjectDetails{
17+					session: session,
18+					store:   store,
19+				}
20+				err = pd.rmProjectAssets(user.ID, project.Name)
21 				if err != nil {
22 					log.Error(err)
23-					return
24-				}
25-
26-				if len(fileList) > 0 {
27-					out := fmt.Sprintf("(%s) assets now orphaned, deleting files (%d) ...\n", projectName, len(fileList))
28-					_, _ = session.Write([]byte(out))
29+					utils.ErrorHandler(session, err)
30 				}
31 
32-				for _, file := range fileList {
33-					err = store.DeleteFile(bucket, file.Name())
34-					if err == nil {
35-						_, _ = session.Write([]byte(fmt.Sprintf("deleted orphaned (%s)\n", file.Name())))
36-					} else {
37-						log.Error(err)
38-						utils.ErrorHandler(session, err)
39-					}
40-				} */
41-
42-				out := fmt.Sprintf("(%s) now points to (%s)\n", projectName, linkTo)
43+				out = fmt.Sprintf("(%s) now points to (%s)\n", projectName, linkTo)
44 				_, _ = session.Write([]byte(out))
45 				return
46 			} else if cmd == "links" {