Skip to content

Commit

Permalink
chore: retire legacy api
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Apr 13, 2024
1 parent cf4db17 commit bbd206e
Show file tree
Hide file tree
Showing 22 changed files with 22 additions and 11,119 deletions.
38 changes: 15 additions & 23 deletions internal/jobs/presign_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package jobs

import (
"context"
"encoding/json"
"log/slog"
"strings"
"time"

"github.com/pkg/errors"

"github.com/usememos/memos/plugin/storage/s3"
apiv1 "github.com/usememos/memos/server/route/api/v1"
apiv2pb "github.com/usememos/memos/proto/gen/api/v2"
storepb "github.com/usememos/memos/proto/gen/store"
apiv2 "github.com/usememos/memos/server/route/api/v2"
"github.com/usememos/memos/store"
)

Expand Down Expand Up @@ -95,44 +96,35 @@ func signExternalLinks(ctx context.Context, dataStore *store.Store) error {
// Returns error only in case of internal problems (ie: database or configuration issues).
// May return nil client and nil error.
func findObjectStorage(ctx context.Context, dataStore *store.Store) (*s3.Client, error) {
systemSettingStorageServiceID, err := dataStore.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{Name: apiv1.SystemSettingStorageServiceIDName.String()})
workspaceStorageSetting, err := dataStore.GetWorkspaceStorageSetting(ctx)
if err != nil {
return nil, errors.Wrap(err, "Failed to find SystemSettingStorageServiceIDName")
return nil, errors.Wrap(err, "Failed to find workspaceStorageSetting")
}

storageServiceID := apiv1.DefaultStorage
if systemSettingStorageServiceID != nil {
err = json.Unmarshal([]byte(systemSettingStorageServiceID.Value), &storageServiceID)
if err != nil {
return nil, errors.Wrap(err, "Failed to unmarshal storage service id")
}
if workspaceStorageSetting.StorageType != storepb.WorkspaceStorageSetting_STORAGE_TYPE_EXTERNAL || workspaceStorageSetting.ActivedExternalStorageId == nil {
return nil, nil
}
storage, err := dataStore.GetStorage(ctx, &store.FindStorage{ID: &storageServiceID})
storage, err := dataStore.GetStorageV1(ctx, &store.FindStorage{ID: workspaceStorageSetting.ActivedExternalStorageId})
if err != nil {
return nil, errors.Wrap(err, "Failed to find StorageServiceID")
return nil, errors.Wrap(err, "Failed to find storage")
}

if storage == nil {
return nil, nil // storage not configured - not an error, just return empty ref
return nil, nil
}
storageMessage, err := apiv1.ConvertStorageFromStore(storage)

if err != nil {
return nil, errors.Wrap(err, "Failed to ConvertStorageFromStore")
}
if storageMessage.Type != apiv1.StorageS3 {
storageMessage := apiv2.ConvertStorageFromStore(storage)
if storageMessage.Type != apiv2pb.Storage_S3 {
return nil, nil
}

s3Config := storageMessage.Config.S3Config
s3Config := storageMessage.Config.GetS3Config()
return s3.NewClient(ctx, &s3.Config{
AccessKey: s3Config.AccessKey,
SecretKey: s3Config.SecretKey,
EndPoint: s3Config.EndPoint,
Region: s3Config.Region,
Bucket: s3Config.Bucket,
URLPrefix: s3Config.URLPrefix,
URLSuffix: s3Config.URLSuffix,
URLPrefix: s3Config.UrlPrefix,
URLSuffix: s3Config.UrlSuffix,
PreSign: s3Config.PreSign,
})
}
5 changes: 2 additions & 3 deletions server/integration/telegram.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package integration

import (
"bytes"
"context"
"fmt"
"path/filepath"
Expand All @@ -19,7 +18,6 @@ import (
"github.com/usememos/memos/plugin/telegram"
"github.com/usememos/memos/plugin/webhook"
storepb "github.com/usememos/memos/proto/gen/store"
apiv1 "github.com/usememos/memos/server/route/api/v1"
apiv2 "github.com/usememos/memos/server/route/api/v2"
"github.com/usememos/memos/store"
)
Expand Down Expand Up @@ -126,9 +124,10 @@ func (t *TelegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot,
Type: attachment.GetMimeType(),
Size: attachment.FileSize,
MemoID: &memoMessage.ID,
Blob: attachment.Data,
}

err := apiv1.SaveResourceBlob(ctx, t.store, &create, bytes.NewReader(attachment.Data))
err := apiv2.SaveResourceBlob(ctx, t.store, &create)
if err != nil {
_, err := bot.EditMessage(ctx, message.Chat.ID, reply.MessageID, fmt.Sprintf("Failed to SaveResourceBlob: %s", err), nil)
return err
Expand Down
253 changes: 0 additions & 253 deletions server/route/api/v1/auth.go

This file was deleted.

15 changes: 0 additions & 15 deletions server/route/api/v1/common.go

This file was deleted.

Loading

0 comments on commit bbd206e

Please sign in to comment.