-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(imgs): dont bring libwebp into every service (#55)
Most of our libwebp related code lived inside the `shared` package. This is problematic since every service imports that package, thereby requiring libwebp for every service. Now references to libwebp live solely inside `imgs` library. Unfortunately, all of our post-based SSH services import `imgs` so they still have the requirement.
- Loading branch information
Showing
8 changed files
with
69 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package uploadimgs | ||
|
||
import ( | ||
"github.com/charmbracelet/ssh" | ||
"github.com/picosh/pico/db" | ||
"github.com/picosh/pico/imgs" | ||
"github.com/picosh/pico/shared" | ||
"github.com/picosh/pico/shared/storage" | ||
"github.com/picosh/pico/wish/send/utils" | ||
) | ||
|
||
type ImgsAPI struct { | ||
Cfg *shared.ConfigSite | ||
Db db.DB | ||
St storage.ObjectStorage | ||
} | ||
|
||
func NewImgsAPI(dbpool db.DB, st storage.ObjectStorage) *ImgsAPI { | ||
cfg := imgs.NewConfigSite() | ||
return &ImgsAPI{ | ||
Cfg: cfg, | ||
Db: dbpool, | ||
St: st, | ||
} | ||
} | ||
|
||
func (img *ImgsAPI) HasAccess(userID string) bool { | ||
return img.Db.HasFeatureForUser(userID, "imgs") | ||
} | ||
|
||
func (img *ImgsAPI) Upload(s ssh.Session, file *utils.FileEntry) (string, error) { | ||
handler := NewUploadImgHandler(img.Db, img.Cfg, img.St) | ||
err := handler.Validate(s) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return handler.Write(s, file) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,10 @@ | ||
package imgs | ||
|
||
import ( | ||
"github.com/charmbracelet/ssh" | ||
"github.com/picosh/pico/db" | ||
uploadimgs "github.com/picosh/pico/filehandlers/imgs" | ||
"github.com/picosh/pico/shared" | ||
"github.com/picosh/pico/shared/storage" | ||
"github.com/picosh/pico/wish/send/utils" | ||
) | ||
|
||
type IImgsAPI interface { | ||
HasAccess(userID string) bool | ||
Upload(file *utils.FileEntry) (string, error) | ||
} | ||
|
||
type ImgsAPI struct { | ||
Cfg *shared.ConfigSite | ||
Db db.DB | ||
St storage.ObjectStorage | ||
} | ||
|
||
func NewImgsAPI(dbpool db.DB, st storage.ObjectStorage) *ImgsAPI { | ||
cfg := NewConfigSite() | ||
return &ImgsAPI{ | ||
Cfg: cfg, | ||
Db: dbpool, | ||
St: st, | ||
} | ||
} | ||
|
||
func (img *ImgsAPI) HasAccess(userID string) bool { | ||
return img.Db.HasFeatureForUser(userID, "imgs") | ||
} | ||
|
||
func (img *ImgsAPI) Upload(s ssh.Session, file *utils.FileEntry) (string, error) { | ||
handler := uploadimgs.NewUploadImgHandler(img.Db, img.Cfg, img.St) | ||
err := handler.Validate(s) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return handler.Write(s, file) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters