Skip to content

Commit

Permalink
refactor: Cleaning double closing script, deprecated thumbnail script
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Aug 7, 2022
1 parent 5bded81 commit edde7f6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 119 deletions.
106 changes: 0 additions & 106 deletions cmd/fibr/static/scripts/thumbnail.js

This file was deleted.

4 changes: 1 addition & 3 deletions cmd/fibr/templates/async-image.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
* Async image loading
*/
async function fetchThumbnail() {
fetchURL = document.location.search;
let fetchURL = document.location.search;
if (fetchURL.includes('?')) {
fetchURL += '&thumbnail';
} else {
Expand Down Expand Up @@ -154,6 +154,4 @@
false,
);
</script>

</script>
{{ end }}
9 changes: 9 additions & 0 deletions pkg/provider/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ func (e Event) GetURL() string {
return e.URL
}

func (e Event) BrowserURL() string {
return e.GetURL() + "?browser"
}

func (e Event) StoryURL(id string) string {
url := e.GetURL()
return fmt.Sprintf("%s/?d=story#%s", url[:strings.LastIndex(url, "/")], id)
}

// GetName returns the name of the item
func (e Event) GetName() string {
if e.New != nil {
Expand Down
18 changes: 8 additions & 10 deletions pkg/webhook/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,25 @@ func (a *App) discordHandle(ctx context.Context, webhook provider.Webhook, event
return send(ctx, webhook.ID, request.Post(webhook.URL), discord.NewDataResponse(a.eventText(event)))
}

url := event.GetURL()
title := path.Base(path.Dir(event.Item.Pathname))
if title == "/" {
title = "fibr"
}

var description string
var url, description string
fields := []discord.Field{discord.NewField("item", event.GetName())}

switch event.Type {
case provider.UploadEvent:
description = "💾 A file has been uploaded"
url += "?browser"
url = event.BrowserURL()
case provider.RenameEvent:
description = "✏️ An item has been renamed"
fields = append(fields, discord.NewField("to", event.GetTo()))
url += "?browser"
url = event.BrowserURL()
case provider.DescriptionEvent:
description = "💬 " + event.Metadata["description"]
url = fmt.Sprintf("%s/?d=story#%s", url[:strings.LastIndex(url, "/")], event.Item.ID)
url = event.StoryURL(event.Item.ID)
}

embed := discord.Embed{
Expand Down Expand Up @@ -135,26 +134,25 @@ func (a *App) slackHandle(ctx context.Context, webhook provider.Webhook, event p
return send(ctx, webhook.ID, request.Post(webhook.URL), slack.NewResponse(a.eventText(event)))
}

url := event.GetURL()
title := path.Base(path.Dir(event.Item.Pathname))
if title == "/" {
title = "fibr"
}

var description string
var url, description string
var extraField slack.Text

switch event.Type {
case provider.UploadEvent:
description = "💾 A file has been uploaded"
url += "?browser"
url = event.BrowserURL()
case provider.RenameEvent:
description = "✏️ An item has been renamed"
extraField = slack.NewText(fmt.Sprintf("*to*\n%s", event.GetTo()))
url += "?browser"
url = event.BrowserURL()
case provider.DescriptionEvent:
description = "💬 " + event.Metadata["description"]
url = fmt.Sprintf("%s/?d=story#%s", url[:strings.LastIndex(url, "/")], event.Item.ID)
url = event.StoryURL(event.Item.ID)
}

section := slack.NewSection(slack.NewText(description)).AddField(slack.NewText(fmt.Sprintf("*item*\n%s", event.GetName())))
Expand Down

0 comments on commit edde7f6

Please sign in to comment.