Compare commits
No commits in common. "37e0d7940e4a0ca3285f94c29c8f6a71c3309807" and "8bae137886ba5ac5493d0d1a4b7ca09660580308" have entirely different histories.
37e0d7940e
...
8bae137886
6 changed files with 9 additions and 23 deletions
|
@ -2,8 +2,6 @@ IMAGE_PATH=/tmp
|
||||||
REDIRECT_URI=http://localhost:8081/api/auth/callback
|
REDIRECT_URI=http://localhost:8081/api/auth/callback
|
||||||
CLIENT_ID=
|
CLIENT_ID=
|
||||||
CLIENT_SECRET=
|
CLIENT_SECRET=
|
||||||
FRONTEND_URI=
|
|
||||||
DOMAIN=localhost
|
|
||||||
PORT=
|
PORT=
|
||||||
|
|
||||||
# can be either postgres or sqlite
|
# can be either postgres or sqlite
|
||||||
|
|
|
@ -38,13 +38,10 @@ func RegisterAuthRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: redirect to dashboard
|
// TODO: redirect to dashboard
|
||||||
/*c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"jwt": jwt,
|
"jwt": jwt,
|
||||||
"known": res.RowsAffected == 0,
|
"known": res.RowsAffected == 0,
|
||||||
})
|
})
|
||||||
*/
|
|
||||||
c.SetCookie("jwt", jwt, int(t.ExpiresIn), "", cfg.Domain, true, true)
|
|
||||||
c.Redirect(http.StatusTemporaryRedirect, cfg.FrontendUri)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
api.GET("/auth/me", auth.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
api.GET("/auth/me", auth.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
||||||
|
|
|
@ -48,6 +48,7 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||||
|
|
||||||
fileMeta := types.File{
|
fileMeta := types.File{
|
||||||
ID: uid + "_" + file.Filename,
|
ID: uid + "_" + file.Filename,
|
||||||
|
Path: filePath,
|
||||||
Owner: uid,
|
Owner: uid,
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
Size: file.Size,
|
Size: file.Size,
|
||||||
|
|
|
@ -15,17 +15,16 @@ type Route struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type StereoConfig struct {
|
type StereoConfig struct {
|
||||||
ImagePath string
|
ImagePath string
|
||||||
Router *gin.Engine
|
Router *gin.Engine
|
||||||
Client client.Client
|
Client client.Client
|
||||||
Database *gorm.DB
|
Database *gorm.DB
|
||||||
JWTSecret string
|
JWTSecret string
|
||||||
FrontendUri string
|
|
||||||
Domain string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
ID string `gorm:"primaryKey"`
|
ID string `gorm:"primaryKey"`
|
||||||
|
Path string `gorm:"not null;index"`
|
||||||
Owner string `gorm:"not null;index"`
|
Owner string `gorm:"not null;index"`
|
||||||
Size int64 `gorm:"not null;type:bigint"`
|
Size int64 `gorm:"not null;type:bigint"`
|
||||||
CreatedAt time.Time `gorm:"autoCreateTime"`
|
CreatedAt time.Time `gorm:"autoCreateTime"`
|
||||||
|
|
7
main.go
7
main.go
|
@ -54,14 +54,9 @@ func main() {
|
||||||
requireEnv("CLIENT_ID"),
|
requireEnv("CLIENT_ID"),
|
||||||
requireEnv("CLIENT_SECRET"),
|
requireEnv("CLIENT_SECRET"),
|
||||||
),
|
),
|
||||||
FrontendUri: requireEnv("FRONTEND_URI"),
|
|
||||||
Domain: requireEnv("DOMAIN"),
|
|
||||||
JWTSecret: requireEnv("JWT_SECRET"),
|
JWTSecret: requireEnv("JWT_SECRET"),
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println(c.Domain)
|
|
||||||
log.Println(c.FrontendUri)
|
|
||||||
|
|
||||||
switch databaseType {
|
switch databaseType {
|
||||||
case "sqlite":
|
case "sqlite":
|
||||||
db, err := gorm.Open(sqlite.Open(sqliteFile), &gorm.Config{})
|
db, err := gorm.Open(sqlite.Open(sqliteFile), &gorm.Config{})
|
||||||
|
@ -91,6 +86,6 @@ func main() {
|
||||||
c.Database.AutoMigrate(&auth.User{}, &types.File{})
|
c.Database.AutoMigrate(&auth.User{}, &types.File{})
|
||||||
|
|
||||||
api.Register(&c)
|
api.Register(&c)
|
||||||
fmt.Printf("Running on port %s\n", getEnv("PORT", "8081"))
|
fmt.Printf("Running on port %s\n", getEnv("PORT", "8080"))
|
||||||
c.Router.Run()
|
c.Router.Run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
## curl
|
|
||||||
### uploading
|
|
||||||
|
|
||||||
curl -F "file=@(path_to_test_img)" "http://localhost:8081/api/upload" -H "Authorization: Bearer (jwt here)"
|
|
Loading…
Add table
Add a link
Reference in a new issue