Skip to content

Commit

Permalink
chore(deps): Bumping absto to use sha256 instead
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Aug 8, 2022
1 parent 336d51b commit 6055a5d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/fibr/templates/upload-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*/
async function sha1(data) {
const buffer = await crypto.subtle.digest(
'SHA-1',
'SHA-256',
new TextEncoder('utf-8').encode(data),
);
return bufferToHex(buffer);
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/ViBiOh/ChatPotte v0.1.0
github.com/ViBiOh/absto v0.6.2
github.com/ViBiOh/absto v1.0.0
github.com/ViBiOh/auth/v2 v2.13.0
github.com/ViBiOh/exas v0.5.0
github.com/ViBiOh/flags v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ViBiOh/ChatPotte v0.1.0 h1:HfTr5fMaaB+PNi3fzkJk3abKx6Kbv24v5fSyD/Yubgg=
github.com/ViBiOh/ChatPotte v0.1.0/go.mod h1:za3YZFVRpJ3x1zeXFj1wudQ5DGwnrC9qZ9CNr25TYxA=
github.com/ViBiOh/absto v0.6.2 h1:KRNEufp/jT5Onvn//wR3OiOQnGRQ8TztCztAskJBk1E=
github.com/ViBiOh/absto v0.6.2/go.mod h1:ZoXcCx5C+xU9R6SBP4HPXSjf3WZcaVIfFCciiViZfCs=
github.com/ViBiOh/absto v1.0.0 h1:xhmGyH6emqoBrkbCkTnvN25bvttKgWAyPwhu1v4VAG8=
github.com/ViBiOh/absto v1.0.0/go.mod h1:ZoXcCx5C+xU9R6SBP4HPXSjf3WZcaVIfFCciiViZfCs=
github.com/ViBiOh/auth/v2 v2.13.0 h1:AGPU5WFefkZHvLJkWA8bpMb0a2hu9zJNoYOiz7NLKpQ=
github.com/ViBiOh/auth/v2 v2.13.0/go.mod h1:eGqz0ln1SdfuOG8N2XsruKh8NCU7Plx0P5mQPHsNWxQ=
github.com/ViBiOh/exas v0.5.0 h1:ZL5v5rUOkkwo6PxhbOVe96L0RUre7SfStaVcqhE/IbU=
Expand Down
4 changes: 4 additions & 0 deletions pkg/exif/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func (a App) EventConsumer(ctx context.Context, e provider.Event) {

switch e.Type {
case provider.StartEvent:
if err := provider.RenamePreviousID(ctx, a.storageApp, e.Item, ".json", a.Rename); err != nil {
logger.Error("rename from previous ID: %s", err)
}

if err = a.handleStartEvent(ctx, e); err != nil {
getEventLogger(e.Item).Error("start: %s", err)
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package provider

import (
"context"
"crypto/sha1"
"encoding/hex"
"path"
"path/filepath"

absto "github.com/ViBiOh/absto/pkg/model"
Expand Down Expand Up @@ -44,3 +48,23 @@ func MetadataDirectory(item absto.Item) string {

return Dirname(MetadataDirectoryName + pathname)
}

func itemPreviousID(item absto.Item) string {
hasher := sha1.New()
_, _ = hasher.Write([]byte(item.Pathname))
return hex.EncodeToString(hasher.Sum(nil))
}

func RenamePreviousID(ctx context.Context, storageApp absto.Storage, item absto.Item, suffix string, renameFunc func(context.Context, absto.Item, absto.Item) error) error {
if _, err := storageApp.Info(ctx, path.Join(MetadataDirectory(item), itemPreviousID(item)+suffix)); err != nil {
if absto.IsNotExist(err) {
return nil
}
return err
}

previous := item
previous.ID = itemPreviousID(previous)

return renameFunc(ctx, previous, item)
}
3 changes: 3 additions & 0 deletions pkg/thumbnail/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func (a App) EventConsumer(ctx context.Context, e provider.Event) {

switch e.Type {
case provider.StartEvent:
if err := provider.RenamePreviousID(ctx, a.storageApp, e.Item, ".webp", a.Rename); err != nil {
logger.Error("rename from previous ID: %s", err)
}
fallthrough
case provider.UploadEvent:
a.generateItem(ctx, e)
Expand Down

0 comments on commit 6055a5d

Please sign in to comment.