Skip to content

Commit b19a339

Browse files
committed
added save and export feature
1 parent a92d475 commit b19a339

File tree

5 files changed

+75
-34
lines changed

5 files changed

+75
-34
lines changed

backend/routes.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
package main
22

33
import (
4-
"github.com/gin-contrib/gzip"
54
"github.com/gin-contrib/cors"
5+
"github.com/gin-contrib/gzip"
66
"github.com/gin-gonic/gin"
77
)
88

99
func setupRouter() *gin.Engine {
1010
router := gin.Default()
1111
router.Use(gzip.Gzip(gzip.DefaultCompression))
1212
config := cors.DefaultConfig()
13-
config.AllowOrigins = []string{"http://localhost:3000"}
13+
config.AllowOrigins = []string{"http://localhost:3000"}
1414
config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE"}
15-
config.AllowHeaders = append(config.AllowHeaders, "Authorization")
15+
config.AllowHeaders = append(config.AllowHeaders, "Authorization")
1616
router.Use(cors.New(config))
1717
v1 := router.Group("/api/v1")
1818
{
1919
v1.POST("/signup", signup)
2020
v1.POST("/login", login)
21-
v1.POST("/upload",authMiddleware,upload)
22-
v1.GET("/undo",undo)
23-
v1.GET("/redo",redo)
24-
v1.POST("/crop",authMiddleware,crop)
25-
v1.POST("/resize",authMiddleware)
26-
v1.POST("/rotate",authMiddleware,rotate)
27-
v1.POST("/color",authMiddleware)
28-
v1.POST("/filter",authMiddleware)
29-
v1.GET("/export",authMiddleware)
30-
v1.POST("/getImage",authMiddleware,getImage)
21+
v1.POST("/upload", authMiddleware, upload)
22+
v1.GET("/undo", undo)
23+
v1.GET("/redo", redo)
24+
v1.POST("/crop", authMiddleware, crop)
25+
v1.POST("/resize", authMiddleware)
26+
v1.POST("/rotate", authMiddleware, rotate)
27+
v1.POST("/color", authMiddleware)
28+
v1.POST("/filter", authMiddleware)
29+
v1.GET("/export", authMiddleware, export)
30+
v1.GET("/save", authMiddleware, save)
31+
v1.GET("/getImage", authMiddleware, getImage)
3132
}
3233
return router
3334
}

backend/services.go

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ func crop(c *gin.Context) {
200200
}
201201
}
202202

203-
// func imageCenter(img gocv.Mat) image.Point {
204-
// height, width := img.Size()[0], img.Size()[1]
205-
// return image.Pt(width/2, height/2)
206-
// }
207203
func rotate(c *gin.Context) {
208204
email, exists := c.Get("email")
209205
if !exists {
@@ -257,3 +253,42 @@ func getImage(c *gin.Context) {
257253
c.JSON(http.StatusInternalServerError, gin.H{"error": "Upload a image first"})
258254
}
259255
}
256+
func export(c *gin.Context) {
257+
email, exists := c.Get("email")
258+
if !exists {
259+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to retrieve email from context"})
260+
return
261+
}
262+
_, exist := userStacks[email.(string)]
263+
if exist {
264+
imageFile := userStacks[email.(string)].CurrentImage.Path
265+
c.File(imageFile)
266+
} else {
267+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Upload a image first"})
268+
}
269+
}
270+
271+
func save(c *gin.Context) {
272+
email, exists := c.Get("email")
273+
if !exists {
274+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to retrieve email from context"})
275+
return
276+
}
277+
_, exist := userStacks[email.(string)]
278+
if exist {
279+
imageFile := userStacks[email.(string)].CurrentImage.Path
280+
data := bson.M{
281+
"ImagePath": imageFile,
282+
"User": email.(string),
283+
}
284+
insertRes, err := client1.Database("users").Collection("image_details").InsertOne(context.Background(), data)
285+
if err != nil {
286+
log.Fatal(err)
287+
}
288+
fmt.Printf("Inserted document with ID %v\n", insertRes.InsertedID)
289+
c.JSON(http.StatusOK, gin.H{"success": insertRes.InsertedID})
290+
291+
} else {
292+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Upload a image first"})
293+
}
294+
}

frontend/src/App.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,16 @@ body{
114114
width: 100%;
115115
}
116116
.buttons > button{
117-
width: 30%;
118-
height: 50px;
117+
width: 45%;
118+
height: 60px;
119119
box-sizing: border-box;
120120
border-radius: 10px;
121121
cursor: pointer;
122122
}
123123
.exp{
124124
position: absolute;
125-
bottom:0;
125+
bottom:0px;
126126
width: 100%;
127-
height: 10%;
128127
}
129128
.exp > button{
130129
width: 50%;
@@ -133,12 +132,13 @@ body{
133132
cursor: pointer;
134133
}
135134
.history{
136-
height: 60%;
135+
height: 55%;
137136
width: 100%;
138137
position: absolute;
139-
bottom: 0px;
138+
bottom: 5%;
140139
right: 0;
141140
background-color: rgb(9, 9, 9);
141+
overflow-y: auto;
142142
}
143143

144144
.upload{

frontend/src/components/History.js

Whitespace-only changes.

frontend/src/components/Main.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,28 @@ export default function Main(props) {
2323
</div>
2424
<div className="sidebar">
2525
<h1 style={{ textAlign: "center" }}>
26-
Hello {localStorage.getItem("Auth").substring(0,10)}
26+
Hello {localStorage.getItem("Auth").substring(0, 10)}
2727
</h1>
2828
<div className="buttons">
2929
<button>CROP</button>
3030
<button>RESIZE</button>
31-
<button>FILTER</button>
3231
<button>ROTATE</button>
33-
<button>COLOR</button>
32+
<button>GRAYSCALE</button>
33+
<button>BLUR</button>
34+
<button>BRIGHTNESS</button>
35+
<button>SHARPENING</button>
36+
<button>contrast</button>
3437
</div>
35-
<div className="history">
36-
<h1 style={{ backgroundColor: "black", textAlign: "center" }}>
37-
History
38-
</h1>
39-
<div className="exp">
40-
<button>Export</button>
41-
<button>Save</button>
42-
</div>
38+
<h1
39+
style={{
40+
textAlign: "center",
41+
}}>
42+
History
43+
</h1>
44+
<div className="history"></div>
45+
<div className="exp">
46+
<button>Export</button>
47+
<button>Save</button>
4348
</div>
4449
</div>
4550
</>

0 commit comments

Comments
 (0)