Skip to content

Commit

Permalink
chore:ci: pull heads/release/0.20.1 from usememos/memos
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthalles committed Mar 8, 2024
2 parents ab8c573 + 472fd2c commit 2240bc8
Show file tree
Hide file tree
Showing 125 changed files with 3,122 additions and 3,736 deletions.
74 changes: 0 additions & 74 deletions memos/.github/workflows/codeql.yml

This file was deleted.

6 changes: 2 additions & 4 deletions memos/.github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Close Stale Issues

on:
schedule:
- cron: "0 0 * * *"
- cron: "0 */8 * * *"

jobs:
stale:
Expand All @@ -13,7 +13,5 @@ jobs:
steps:
- uses: actions/stale@v9.0.0
with:
stale-issue-message: "This issue is stale because it has been open 14 days with no activity."
close-issue-message: "This issue was closed because it has been stalled for 28 days with no activity."
days-before-issue-stale: 14
days-before-issue-close: 14
days-before-issue-close: 7
17 changes: 7 additions & 10 deletions memos/bin/memos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ package main
import (
"context"
"fmt"
"log/slog"
"net/http"
"os"
"os/signal"
"syscall"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"

"github.com/usememos/memos/internal/jobs"
"github.com/usememos/memos/internal/log"
"github.com/usememos/memos/server"
_profile "github.com/usememos/memos/server/profile"
"github.com/usememos/memos/store"
Expand Down Expand Up @@ -49,26 +48,26 @@ var (
dbDriver, err := db.NewDBDriver(profile)
if err != nil {
cancel()
log.Error("failed to create db driver", zap.Error(err))
slog.Error("failed to create db driver", err)
return
}
if err := dbDriver.Migrate(ctx); err != nil {
cancel()
log.Error("failed to migrate db", zap.Error(err))
slog.Error("failed to migrate database", err)
return
}

storeInstance := store.New(dbDriver, profile)
if err := storeInstance.MigrateManually(ctx); err != nil {
cancel()
log.Error("failed to migrate manually", zap.Error(err))
slog.Error("failed to migrate manually", err)
return
}

s, err := server.NewServer(ctx, profile, storeInstance)
if err != nil {
cancel()
log.Error("failed to create server", zap.Error(err))
slog.Error("failed to create server", err)
return
}

Expand All @@ -78,8 +77,7 @@ var (
// which is taken as the graceful shutdown signal for many systems, eg., Kubernetes, Gunicorn.
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
sig := <-c
log.Info(fmt.Sprintf("%s received.\n", sig.String()))
<-c
s.Shutdown(ctx)
cancel()
}()
Expand All @@ -91,7 +89,7 @@ var (

if err := s.Start(ctx); err != nil {
if err != http.ErrServerClosed {
log.Error("failed to start server", zap.Error(err))
slog.Error("failed to start server", err)
cancel()
}
}
Expand All @@ -103,7 +101,6 @@ var (
)

func Execute() error {
defer log.Sync()
return rootCmd.Execute()
}

Expand Down
3 changes: 1 addition & 2 deletions memos/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ require (
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
github.com/swaggo/swag v1.16.3
github.com/yourselfhosted/gomark v0.0.0-20240222150908-75b2b15a7837
go.uber.org/zap v1.26.0
github.com/yourselfhosted/gomark v0.0.0-20240228170507-6a73bfad2eb6
golang.org/x/crypto v0.19.0
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
golang.org/x/mod v0.15.0
Expand Down
8 changes: 2 additions & 6 deletions memos/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/yourselfhosted/gomark v0.0.0-20240222150908-75b2b15a7837 h1:TAFqMn/ey7NykzAtE0rJCy/4f2OIp8uAJZti7WfVSpo=
github.com/yourselfhosted/gomark v0.0.0-20240222150908-75b2b15a7837/go.mod h1:dfl9FHGIw1oISjPc16u8n6/H/dngiVfdVRtS5+WJ4Js=
github.com/yourselfhosted/gomark v0.0.0-20240228170507-6a73bfad2eb6 h1:6h74aOL7vOgWX1TG2zwrUgSWm+isZhSKpmoOygO7Wlg=
github.com/yourselfhosted/gomark v0.0.0-20240228170507-6a73bfad2eb6/go.mod h1:dfl9FHGIw1oISjPc16u8n6/H/dngiVfdVRtS5+WJ4Js=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
Expand All @@ -474,17 +474,13 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
12 changes: 5 additions & 7 deletions memos/internal/jobs/presign_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@ package jobs
import (
"context"
"encoding/json"
"log/slog"
"strings"
"time"

"github.com/pkg/errors"
"go.uber.org/zap"

apiv1 "github.com/usememos/memos/api/v1"
"github.com/usememos/memos/internal/log"
"github.com/usememos/memos/plugin/storage/s3"
apiv1 "github.com/usememos/memos/server/route/api/v1"
"github.com/usememos/memos/store"
)

// RunPreSignLinks is a background job that pre-signs external links stored in the database.
// It uses S3 client to generate presigned URLs and updates the corresponding resources in the store.
func RunPreSignLinks(ctx context.Context, dataStore *store.Store) {
for {
started := time.Now()
if err := signExternalLinks(ctx, dataStore); err != nil {
log.Warn("failed sign external links", zap.Error(err))
slog.Error("failed to pre-sign links", err)
} else {
log.Info("links pre-signed", zap.Duration("duration", time.Since(started)))
slog.Debug("pre-signed links")
}
select {
case <-time.After(s3.LinkLifetime / 2):
Expand Down Expand Up @@ -69,7 +67,7 @@ func signExternalLinks(ctx context.Context, dataStore *store.Store) error {
}
newLink, err := objectStore.PreSignLink(ctx, res.ExternalLink)
if err != nil {
log.Warn("failed pre-sign link", zap.Int32("resource", res.ID), zap.String("link", res.ExternalLink), zap.Error(err))
slog.Error("failed to pre-sign link", err)
continue // do not fail - we may want update left over links too
}
now := time.Now().Unix()
Expand Down
66 changes: 0 additions & 66 deletions memos/internal/log/logger.go

This file was deleted.

9 changes: 2 additions & 7 deletions memos/plugin/telegram/attachment.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package telegram

import (
"log/slog"
"path/filepath"

"go.uber.org/zap"

"github.com/usememos/memos/internal/log"
)

type Attachment struct {
Expand All @@ -29,9 +26,7 @@ func (b Attachment) GetMimeType() string {

mime, ok := mimeTypes[filepath.Ext(b.FileName)]
if !ok {
// Handle unknown file extension
log.Warn("Unknown file type for ", zap.String("filename", b.FileName))

slog.Warn("Unknown file extension", slog.String("file", b.FileName))
return "application/octet-stream"
}

Expand Down
15 changes: 5 additions & 10 deletions memos/plugin/telegram/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ package telegram
import (
"context"
"errors"
"fmt"
"log/slog"
"strings"
"time"

"go.uber.org/zap"

"github.com/usememos/memos/internal/log"
)

type Handler interface {
Expand Down Expand Up @@ -41,7 +37,6 @@ func (b *Bot) Start(ctx context.Context) {
continue
}
if err != nil {
log.Warn("fail to telegram.GetUpdates", zap.Error(err))
time.Sleep(errRetryWait)
continue
}
Expand All @@ -56,7 +51,7 @@ func (b *Bot) Start(ctx context.Context) {
if update.CallbackQuery != nil {
err := b.handler.CallbackQueryHandle(ctx, b, *update.CallbackQuery)
if err != nil {
log.Error("fail to handle CallbackQuery", zap.Error(err))
slog.Error("fail to handle callback query", err)
}

continue
Expand All @@ -70,7 +65,7 @@ func (b *Bot) Start(ctx context.Context) {
if !message.IsSupported() {
_, err := b.SendReplyMessage(ctx, message.Chat.ID, message.MessageID, "Supported messages: animation, audio, text, document, photo, video, video note, voice, other messages with caption")
if err != nil {
log.Error(fmt.Sprintf("fail to telegram.SendReplyMessage for messageID=%d", message.MessageID), zap.Error(err))
slog.Error("fail to send reply message", err)
}
continue
}
Expand All @@ -88,12 +83,12 @@ func (b *Bot) Start(ctx context.Context) {

err = b.handleSingleMessages(ctx, singleMessages)
if err != nil {
log.Error("fail to handle singleMessage", zap.Error(err))
slog.Error("fail to handle plain text message", err)
}

err = b.handleGroupMessages(ctx, groupMessages)
if err != nil {
log.Error("fail to handle plain text message", zap.Error(err))
slog.Error("fail to handle media group message", err)
}
}
}
Expand Down
Loading

0 comments on commit 2240bc8

Please sign in to comment.