2022-02-03 10:32:03 +03:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2023-01-11 19:00:44 +03:00
|
|
|
"bytes"
|
2023-05-26 04:43:51 +03:00
|
|
|
"context"
|
2022-02-04 11:51:48 +03:00
|
|
|
"encoding/json"
|
2022-02-03 10:32:03 +03:00
|
|
|
"fmt"
|
2022-08-20 06:36:24 +03:00
|
|
|
"io"
|
2023-06-08 17:35:33 +03:00
|
|
|
"mime"
|
2022-02-03 10:32:03 +03:00
|
|
|
"net/http"
|
2022-12-12 15:00:21 +03:00
|
|
|
"net/url"
|
2023-03-19 14:37:57 +03:00
|
|
|
"os"
|
2023-03-06 15:04:19 +03:00
|
|
|
"path"
|
2023-03-19 14:37:57 +03:00
|
|
|
"path/filepath"
|
2023-03-09 17:41:48 +03:00
|
|
|
"regexp"
|
2022-02-03 10:32:03 +03:00
|
|
|
"strconv"
|
2023-01-07 05:51:34 +03:00
|
|
|
"strings"
|
2023-05-22 06:08:49 +03:00
|
|
|
"sync/atomic"
|
2022-10-29 10:40:09 +03:00
|
|
|
"time"
|
2022-02-03 10:32:03 +03:00
|
|
|
|
2023-05-20 03:39:39 +03:00
|
|
|
"github.com/disintegration/imaging"
|
2023-02-13 14:36:48 +03:00
|
|
|
"github.com/labstack/echo/v4"
|
2023-01-02 18:18:12 +03:00
|
|
|
"github.com/pkg/errors"
|
2022-06-27 17:09:06 +03:00
|
|
|
"github.com/usememos/memos/api"
|
2023-07-02 13:56:25 +03:00
|
|
|
apiv1 "github.com/usememos/memos/api/v1"
|
2022-09-03 13:54:22 +03:00
|
|
|
"github.com/usememos/memos/common"
|
2023-04-03 12:02:47 +03:00
|
|
|
"github.com/usememos/memos/common/log"
|
2023-02-13 14:36:48 +03:00
|
|
|
"github.com/usememos/memos/plugin/storage/s3"
|
2023-05-26 04:43:51 +03:00
|
|
|
"github.com/usememos/memos/store"
|
2023-04-03 12:02:47 +03:00
|
|
|
"go.uber.org/zap"
|
2022-02-03 10:32:03 +03:00
|
|
|
)
|
|
|
|
|
2022-11-18 16:17:52 +03:00
|
|
|
const (
|
2023-05-13 17:27:28 +03:00
|
|
|
// The upload memory buffer is 32 MiB.
|
|
|
|
// It should be kept low, so RAM usage doesn't get out of control.
|
|
|
|
// This is unrelated to maximum upload size limit, which is now set through system setting.
|
|
|
|
maxUploadBufferSizeBytes = 32 << 20
|
|
|
|
MebiByte = 1024 * 1024
|
2023-05-20 03:39:39 +03:00
|
|
|
|
|
|
|
// thumbnailImagePath is the directory to store image thumbnails.
|
|
|
|
thumbnailImagePath = ".thumbnail_cache"
|
2022-11-18 16:17:52 +03:00
|
|
|
)
|
|
|
|
|
2023-03-09 17:41:48 +03:00
|
|
|
var fileKeyPattern = regexp.MustCompile(`\{[a-z]{1,9}\}`)
|
|
|
|
|
2022-02-03 10:32:03 +03:00
|
|
|
func (s *Server) registerResourceRoutes(g *echo.Group) {
|
|
|
|
g.POST("/resource", func(c echo.Context) error {
|
2022-08-07 05:17:12 +03:00
|
|
|
ctx := c.Request().Context()
|
2022-07-28 15:09:25 +03:00
|
|
|
userID, ok := c.Get(getUserIDContextKey()).(int)
|
|
|
|
if !ok {
|
|
|
|
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
|
|
|
}
|
2022-02-03 10:32:03 +03:00
|
|
|
|
2023-01-21 03:46:49 +03:00
|
|
|
resourceCreate := &api.ResourceCreate{}
|
|
|
|
if err := json.NewDecoder(c.Request().Body).Decode(resourceCreate); err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post resource request").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resourceCreate.CreatorID = userID
|
2023-06-08 17:35:33 +03:00
|
|
|
if resourceCreate.ExternalLink != "" {
|
|
|
|
// Only allow those external links scheme with http/https
|
|
|
|
linkURL, err := url.Parse(resourceCreate.ExternalLink)
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Invalid external link").SetInternal(err)
|
|
|
|
}
|
|
|
|
if linkURL.Scheme != "http" && linkURL.Scheme != "https" {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Invalid external link scheme")
|
|
|
|
}
|
|
|
|
|
|
|
|
if resourceCreate.DownloadToLocal {
|
|
|
|
resp, err := http.Get(linkURL.String())
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Failed to request "+resourceCreate.ExternalLink)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
blob, err := io.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Failed to read "+resourceCreate.ExternalLink)
|
|
|
|
}
|
|
|
|
resourceCreate.Blob = blob
|
|
|
|
|
|
|
|
mediaType, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type"))
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Failed to read mime from "+resourceCreate.ExternalLink)
|
|
|
|
}
|
|
|
|
resourceCreate.Type = mediaType
|
|
|
|
|
|
|
|
filename := path.Base(linkURL.Path)
|
|
|
|
if path.Ext(filename) == "" {
|
|
|
|
extensions, _ := mime.ExtensionsByType(mediaType)
|
|
|
|
if len(extensions) > 0 {
|
|
|
|
filename += extensions[0]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resourceCreate.Filename = filename
|
|
|
|
resourceCreate.PublicID = common.GenUUID()
|
|
|
|
resourceCreate.ExternalLink = ""
|
|
|
|
}
|
2023-02-11 12:34:29 +03:00
|
|
|
}
|
2023-02-27 17:16:33 +03:00
|
|
|
|
2023-01-21 03:46:49 +03:00
|
|
|
resource, err := s.Store.CreateResource(ctx, resourceCreate)
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create resource").SetInternal(err)
|
|
|
|
}
|
2023-07-02 13:56:25 +03:00
|
|
|
if err := s.createResourceCreateActivity(ctx, resource); err != nil {
|
2023-01-21 03:46:49 +03:00
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)
|
|
|
|
}
|
2023-02-17 18:55:56 +03:00
|
|
|
return c.JSON(http.StatusOK, composeResponse(resource))
|
2023-01-21 03:46:49 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
g.POST("/resource/blob", func(c echo.Context) error {
|
|
|
|
ctx := c.Request().Context()
|
|
|
|
userID, ok := c.Get(getUserIDContextKey()).(int)
|
|
|
|
if !ok {
|
|
|
|
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
|
|
|
}
|
|
|
|
|
2023-05-15 16:54:13 +03:00
|
|
|
// This is the backend default max upload size limit.
|
2023-07-02 13:56:25 +03:00
|
|
|
maxUploadSetting := s.Store.GetSystemSettingValueWithDefault(&ctx, apiv1.SystemSettingMaxUploadSizeMiBName.String(), "32")
|
2023-05-13 17:27:28 +03:00
|
|
|
var settingMaxUploadSizeBytes int
|
|
|
|
if settingMaxUploadSizeMiB, err := strconv.Atoi(maxUploadSetting); err == nil {
|
|
|
|
settingMaxUploadSizeBytes = settingMaxUploadSizeMiB * MebiByte
|
|
|
|
} else {
|
|
|
|
log.Warn("Failed to parse max upload size", zap.Error(err))
|
|
|
|
settingMaxUploadSizeBytes = 0
|
2022-02-03 10:32:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
file, err := c.FormFile("file")
|
|
|
|
if err != nil {
|
2022-11-18 16:17:52 +03:00
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to get uploading file").SetInternal(err)
|
|
|
|
}
|
|
|
|
if file == nil {
|
2022-02-03 10:32:03 +03:00
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Upload file not found").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
2023-05-13 17:27:28 +03:00
|
|
|
if file.Size > int64(settingMaxUploadSizeBytes) {
|
|
|
|
message := fmt.Sprintf("File size exceeds allowed limit of %d MiB", settingMaxUploadSizeBytes/MebiByte)
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, message).SetInternal(err)
|
|
|
|
}
|
|
|
|
if err := c.Request().ParseMultipartForm(maxUploadBufferSizeBytes); err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Failed to parse upload data").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
2022-02-03 10:32:03 +03:00
|
|
|
filetype := file.Header.Get("Content-Type")
|
|
|
|
size := file.Size
|
2023-04-03 09:13:22 +03:00
|
|
|
sourceFile, err := file.Open()
|
2022-02-03 10:32:03 +03:00
|
|
|
if err != nil {
|
2022-02-04 13:54:24 +03:00
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to open file").SetInternal(err)
|
2022-02-03 10:32:03 +03:00
|
|
|
}
|
2023-04-03 09:13:22 +03:00
|
|
|
defer sourceFile.Close()
|
2022-02-03 10:32:03 +03:00
|
|
|
|
2023-04-03 18:16:43 +03:00
|
|
|
var resourceCreate *api.ResourceCreate
|
2023-07-02 13:56:25 +03:00
|
|
|
systemSettingStorageServiceID, err := s.Store.GetSystemSetting(ctx, &store.FindSystemSetting{Name: apiv1.SystemSettingStorageServiceIDName.String()})
|
|
|
|
if err != nil {
|
2023-02-13 14:36:48 +03:00
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find storage").SetInternal(err)
|
|
|
|
}
|
2023-04-03 09:13:22 +03:00
|
|
|
storageServiceID := api.DatabaseStorage
|
2023-03-19 14:37:57 +03:00
|
|
|
if systemSettingStorageServiceID != nil {
|
|
|
|
err = json.Unmarshal([]byte(systemSettingStorageServiceID.Value), &storageServiceID)
|
2023-02-14 04:56:04 +03:00
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal storage service id").SetInternal(err)
|
|
|
|
}
|
|
|
|
}
|
2023-05-27 04:09:41 +03:00
|
|
|
|
2023-05-15 17:42:12 +03:00
|
|
|
publicID := common.GenUUID()
|
2023-04-03 09:13:22 +03:00
|
|
|
if storageServiceID == api.DatabaseStorage {
|
|
|
|
fileBytes, err := io.ReadAll(sourceFile)
|
2023-02-13 14:36:48 +03:00
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to read file").SetInternal(err)
|
|
|
|
}
|
|
|
|
resourceCreate = &api.ResourceCreate{
|
2023-02-27 17:16:33 +03:00
|
|
|
CreatorID: userID,
|
2023-04-03 18:16:43 +03:00
|
|
|
Filename: file.Filename,
|
2023-02-27 17:16:33 +03:00
|
|
|
Type: filetype,
|
|
|
|
Size: size,
|
|
|
|
Blob: fileBytes,
|
2023-02-13 14:36:48 +03:00
|
|
|
}
|
2023-04-03 09:13:22 +03:00
|
|
|
} else if storageServiceID == api.LocalStorage {
|
2023-05-10 03:03:55 +03:00
|
|
|
// filepath.Join() should be used for local file paths,
|
|
|
|
// as it handles the os-specific path separator automatically.
|
|
|
|
// path.Join() always uses '/' as path separator.
|
2023-07-02 13:56:25 +03:00
|
|
|
systemSettingLocalStoragePath, err := s.Store.GetSystemSetting(ctx, &store.FindSystemSetting{Name: apiv1.SystemSettingLocalStoragePathName.String()})
|
2023-03-19 14:37:57 +03:00
|
|
|
if err != nil && common.ErrorCode(err) != common.NotFound {
|
2023-04-03 09:13:22 +03:00
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find local storage path setting").SetInternal(err)
|
2023-03-19 14:37:57 +03:00
|
|
|
}
|
2023-05-23 14:15:30 +03:00
|
|
|
localStoragePath := "assets/{publicid}"
|
|
|
|
if systemSettingLocalStoragePath != nil && systemSettingLocalStoragePath.Value != "" {
|
2023-03-19 14:37:57 +03:00
|
|
|
err = json.Unmarshal([]byte(systemSettingLocalStoragePath.Value), &localStoragePath)
|
|
|
|
if err != nil {
|
2023-04-03 09:13:22 +03:00
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal local storage path setting").SetInternal(err)
|
2023-03-19 14:37:57 +03:00
|
|
|
}
|
|
|
|
}
|
2023-05-10 03:03:55 +03:00
|
|
|
filePath := filepath.FromSlash(localStoragePath)
|
2023-05-23 14:15:30 +03:00
|
|
|
if !strings.Contains(filePath, "{publicid}") {
|
|
|
|
filePath = filepath.Join(filePath, "{publicid}")
|
2023-03-19 14:37:57 +03:00
|
|
|
}
|
2023-05-23 14:15:30 +03:00
|
|
|
filePath = filepath.Join(s.Profile.Data, replacePathTemplate(filePath, file.Filename, publicID+filepath.Ext(file.Filename)))
|
|
|
|
|
|
|
|
dir := filepath.Dir(filePath)
|
2023-04-03 18:16:43 +03:00
|
|
|
if err = os.MkdirAll(dir, os.ModePerm); err != nil {
|
2023-03-19 14:37:57 +03:00
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create directory").SetInternal(err)
|
|
|
|
}
|
|
|
|
dst, err := os.Create(filePath)
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create file").SetInternal(err)
|
|
|
|
}
|
|
|
|
defer dst.Close()
|
2023-04-03 09:13:22 +03:00
|
|
|
_, err = io.Copy(dst, sourceFile)
|
2023-03-19 14:37:57 +03:00
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to copy file").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resourceCreate = &api.ResourceCreate{
|
|
|
|
CreatorID: userID,
|
2023-05-23 14:15:30 +03:00
|
|
|
Filename: file.Filename,
|
2023-03-19 14:37:57 +03:00
|
|
|
Type: filetype,
|
|
|
|
Size: size,
|
|
|
|
InternalPath: filePath,
|
|
|
|
}
|
2023-02-13 14:36:48 +03:00
|
|
|
} else {
|
2023-02-15 17:54:46 +03:00
|
|
|
storage, err := s.Store.FindStorage(ctx, &api.StorageFind{ID: &storageServiceID})
|
2023-02-13 14:36:48 +03:00
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find storage").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
2023-02-23 19:02:51 +03:00
|
|
|
if storage.Type == api.StorageS3 {
|
|
|
|
s3Config := storage.Config.S3Config
|
2023-04-03 18:16:43 +03:00
|
|
|
s3Client, err := s3.NewClient(ctx, &s3.Config{
|
2023-02-23 19:02:51 +03:00
|
|
|
AccessKey: s3Config.AccessKey,
|
|
|
|
SecretKey: s3Config.SecretKey,
|
|
|
|
EndPoint: s3Config.EndPoint,
|
|
|
|
Region: s3Config.Region,
|
|
|
|
Bucket: s3Config.Bucket,
|
|
|
|
URLPrefix: s3Config.URLPrefix,
|
2023-04-01 10:28:00 +03:00
|
|
|
URLSuffix: s3Config.URLSuffix,
|
2023-02-23 19:02:51 +03:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to new s3 client").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
2023-04-03 18:16:43 +03:00
|
|
|
filePath := s3Config.Path
|
2023-05-23 14:15:30 +03:00
|
|
|
if !strings.Contains(filePath, "{publicid}") {
|
|
|
|
filePath = path.Join(filePath, "{publicid}")
|
2023-04-03 18:16:43 +03:00
|
|
|
}
|
2023-05-23 14:15:30 +03:00
|
|
|
filePath = replacePathTemplate(filePath, file.Filename, publicID+filepath.Ext(file.Filename))
|
2023-04-03 18:16:43 +03:00
|
|
|
_, filename := filepath.Split(filePath)
|
|
|
|
link, err := s3Client.UploadFile(ctx, filePath, filetype, sourceFile)
|
2023-02-23 19:02:51 +03:00
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to upload via s3 client").SetInternal(err)
|
|
|
|
}
|
|
|
|
resourceCreate = &api.ResourceCreate{
|
|
|
|
CreatorID: userID,
|
|
|
|
Filename: filename,
|
|
|
|
Type: filetype,
|
2023-05-09 03:17:26 +03:00
|
|
|
Size: size,
|
2023-02-23 19:02:51 +03:00
|
|
|
ExternalLink: link,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Unsupported storage type")
|
2023-02-13 14:36:48 +03:00
|
|
|
}
|
2022-02-03 10:32:03 +03:00
|
|
|
}
|
|
|
|
|
2023-04-03 09:13:22 +03:00
|
|
|
resourceCreate.PublicID = publicID
|
2022-08-07 05:17:12 +03:00
|
|
|
resource, err := s.Store.CreateResource(ctx, resourceCreate)
|
2022-02-03 10:32:03 +03:00
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create resource").SetInternal(err)
|
|
|
|
}
|
2023-07-02 13:56:25 +03:00
|
|
|
if err := s.createResourceCreateActivity(ctx, resource); err != nil {
|
2023-01-02 18:18:12 +03:00
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)
|
|
|
|
}
|
2023-02-17 18:55:56 +03:00
|
|
|
return c.JSON(http.StatusOK, composeResponse(resource))
|
2022-02-03 10:32:03 +03:00
|
|
|
})
|
2022-02-18 17:21:10 +03:00
|
|
|
|
2022-02-03 10:32:03 +03:00
|
|
|
g.GET("/resource", func(c echo.Context) error {
|
2022-08-07 05:17:12 +03:00
|
|
|
ctx := c.Request().Context()
|
2022-07-28 15:09:25 +03:00
|
|
|
userID, ok := c.Get(getUserIDContextKey()).(int)
|
|
|
|
if !ok {
|
|
|
|
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
|
|
|
}
|
2022-02-03 10:32:03 +03:00
|
|
|
resourceFind := &api.ResourceFind{
|
2022-05-02 21:05:43 +03:00
|
|
|
CreatorID: &userID,
|
2022-02-03 10:32:03 +03:00
|
|
|
}
|
2023-04-01 11:51:20 +03:00
|
|
|
if limit, err := strconv.Atoi(c.QueryParam("limit")); err == nil {
|
|
|
|
resourceFind.Limit = &limit
|
|
|
|
}
|
|
|
|
if offset, err := strconv.Atoi(c.QueryParam("offset")); err == nil {
|
|
|
|
resourceFind.Offset = &offset
|
|
|
|
}
|
|
|
|
|
2022-08-07 05:17:12 +03:00
|
|
|
list, err := s.Store.FindResourceList(ctx, resourceFind)
|
2022-02-03 10:32:03 +03:00
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch resource list").SetInternal(err)
|
|
|
|
}
|
2023-02-17 18:55:56 +03:00
|
|
|
return c.JSON(http.StatusOK, composeResponse(list))
|
2022-06-22 14:16:31 +03:00
|
|
|
})
|
|
|
|
|
2022-12-19 13:45:17 +03:00
|
|
|
g.PATCH("/resource/:resourceId", func(c echo.Context) error {
|
2022-08-07 05:17:12 +03:00
|
|
|
ctx := c.Request().Context()
|
2022-08-06 20:30:48 +03:00
|
|
|
userID, ok := c.Get(getUserIDContextKey()).(int)
|
|
|
|
if !ok {
|
|
|
|
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
|
|
|
}
|
|
|
|
|
2022-05-02 21:05:43 +03:00
|
|
|
resourceID, err := strconv.Atoi(c.Param("resourceId"))
|
2022-02-03 10:32:03 +03:00
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("resourceId"))).SetInternal(err)
|
|
|
|
}
|
|
|
|
|
2022-12-19 13:45:17 +03:00
|
|
|
resourceFind := &api.ResourceFind{
|
2022-12-28 15:22:52 +03:00
|
|
|
ID: &resourceID,
|
2022-11-06 07:21:58 +03:00
|
|
|
}
|
2022-12-28 15:22:52 +03:00
|
|
|
resource, err := s.Store.FindResource(ctx, resourceFind)
|
|
|
|
if err != nil {
|
2022-12-19 13:45:17 +03:00
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find resource").SetInternal(err)
|
2022-11-06 07:21:58 +03:00
|
|
|
}
|
2022-12-28 15:22:52 +03:00
|
|
|
if resource.CreatorID != userID {
|
|
|
|
return echo.NewHTTPError(http.StatusUnauthorized, "Unauthorized")
|
|
|
|
}
|
2022-11-06 07:21:58 +03:00
|
|
|
|
2022-12-19 13:45:17 +03:00
|
|
|
currentTs := time.Now().Unix()
|
|
|
|
resourcePatch := &api.ResourcePatch{
|
|
|
|
UpdatedTs: ¤tTs,
|
2022-02-03 10:32:03 +03:00
|
|
|
}
|
2022-12-19 13:45:17 +03:00
|
|
|
if err := json.NewDecoder(c.Request().Body).Decode(resourcePatch); err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted patch resource request").SetInternal(err)
|
2022-02-03 10:32:03 +03:00
|
|
|
}
|
|
|
|
|
2023-04-03 08:41:27 +03:00
|
|
|
if resourcePatch.ResetPublicID != nil && *resourcePatch.ResetPublicID {
|
|
|
|
publicID := common.GenUUID()
|
|
|
|
resourcePatch.PublicID = &publicID
|
|
|
|
}
|
|
|
|
|
2023-02-09 18:20:36 +03:00
|
|
|
resourcePatch.ID = resourceID
|
2022-12-28 15:22:52 +03:00
|
|
|
resource, err = s.Store.PatchResource(ctx, resourcePatch)
|
2022-12-19 13:45:17 +03:00
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to patch resource").SetInternal(err)
|
|
|
|
}
|
2023-02-17 18:55:56 +03:00
|
|
|
return c.JSON(http.StatusOK, composeResponse(resource))
|
2022-02-03 10:32:03 +03:00
|
|
|
})
|
2022-10-29 10:40:09 +03:00
|
|
|
|
2022-12-19 13:45:17 +03:00
|
|
|
g.DELETE("/resource/:resourceId", func(c echo.Context) error {
|
2022-10-29 10:40:09 +03:00
|
|
|
ctx := c.Request().Context()
|
|
|
|
userID, ok := c.Get(getUserIDContextKey()).(int)
|
|
|
|
if !ok {
|
|
|
|
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
|
|
|
}
|
|
|
|
|
|
|
|
resourceID, err := strconv.Atoi(c.Param("resourceId"))
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("resourceId"))).SetInternal(err)
|
|
|
|
}
|
|
|
|
|
2022-12-19 13:45:17 +03:00
|
|
|
resource, err := s.Store.FindResource(ctx, &api.ResourceFind{
|
2022-10-29 10:40:09 +03:00
|
|
|
ID: &resourceID,
|
|
|
|
CreatorID: &userID,
|
2022-12-19 13:45:17 +03:00
|
|
|
})
|
|
|
|
if err != nil {
|
2022-10-29 10:40:09 +03:00
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find resource").SetInternal(err)
|
|
|
|
}
|
2022-12-28 15:22:52 +03:00
|
|
|
if resource.CreatorID != userID {
|
|
|
|
return echo.NewHTTPError(http.StatusUnauthorized, "Unauthorized")
|
2022-10-29 10:40:09 +03:00
|
|
|
}
|
|
|
|
|
2023-04-03 12:02:47 +03:00
|
|
|
if resource.InternalPath != "" {
|
2023-05-20 03:39:39 +03:00
|
|
|
if err := os.Remove(resource.InternalPath); err != nil {
|
2023-04-03 12:02:47 +03:00
|
|
|
log.Warn(fmt.Sprintf("failed to delete local file with path %s", resource.InternalPath), zap.Error(err))
|
|
|
|
}
|
2023-05-27 04:09:41 +03:00
|
|
|
}
|
2023-05-15 17:42:12 +03:00
|
|
|
|
2023-05-27 04:09:41 +03:00
|
|
|
ext := filepath.Ext(resource.Filename)
|
|
|
|
thumbnailPath := path.Join(s.Profile.Data, thumbnailImagePath, fmt.Sprintf("%d-%s%s", resource.ID, resource.PublicID, ext))
|
|
|
|
if err := os.Remove(thumbnailPath); err != nil {
|
|
|
|
log.Warn(fmt.Sprintf("failed to delete local thumbnail with path %s", thumbnailPath), zap.Error(err))
|
2023-04-03 12:02:47 +03:00
|
|
|
}
|
|
|
|
|
2022-12-19 13:45:17 +03:00
|
|
|
resourceDelete := &api.ResourceDelete{
|
|
|
|
ID: resourceID,
|
2022-10-29 10:40:09 +03:00
|
|
|
}
|
2022-12-19 13:45:17 +03:00
|
|
|
if err := s.Store.DeleteResource(ctx, resourceDelete); err != nil {
|
|
|
|
if common.ErrorCode(err) == common.NotFound {
|
|
|
|
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Resource ID not found: %d", resourceID))
|
|
|
|
}
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete resource").SetInternal(err)
|
2022-10-29 10:40:09 +03:00
|
|
|
}
|
2022-12-19 13:45:17 +03:00
|
|
|
return c.JSON(http.StatusOK, true)
|
2022-10-29 10:40:09 +03:00
|
|
|
})
|
2022-02-03 10:32:03 +03:00
|
|
|
}
|
2022-09-08 19:50:58 +03:00
|
|
|
|
|
|
|
func (s *Server) registerResourcePublicRoutes(g *echo.Group) {
|
2023-04-16 05:31:03 +03:00
|
|
|
// (DEPRECATED) use /r/:resourceId/:publicId/:filename instead.
|
2023-04-03 08:41:27 +03:00
|
|
|
g.GET("/r/:resourceId/:publicId", func(c echo.Context) error {
|
2022-09-08 19:50:58 +03:00
|
|
|
ctx := c.Request().Context()
|
|
|
|
resourceID, err := strconv.Atoi(c.Param("resourceId"))
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("resourceId"))).SetInternal(err)
|
|
|
|
}
|
2023-05-30 14:00:54 +03:00
|
|
|
|
|
|
|
resourceVisibility, err := CheckResourceVisibility(ctx, s.Store, resourceID)
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Failed to get resource visibility").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Protected resource require a logined user
|
|
|
|
userID, ok := c.Get(getUserIDContextKey()).(int)
|
|
|
|
if resourceVisibility == store.Protected && (!ok || userID <= 0) {
|
|
|
|
return echo.NewHTTPError(http.StatusUnauthorized, "Resource visibility not match").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
2023-04-03 08:41:27 +03:00
|
|
|
publicID, err := url.QueryUnescape(c.Param("publicId"))
|
2022-12-12 15:00:21 +03:00
|
|
|
if err != nil {
|
2023-04-03 08:41:27 +03:00
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("publicID is invalid: %s", c.Param("publicId"))).SetInternal(err)
|
2022-12-12 15:00:21 +03:00
|
|
|
}
|
2022-09-08 19:50:58 +03:00
|
|
|
resourceFind := &api.ResourceFind{
|
|
|
|
ID: &resourceID,
|
2023-04-03 08:41:27 +03:00
|
|
|
PublicID: &publicID,
|
2023-01-25 11:11:02 +03:00
|
|
|
GetBlob: true,
|
2022-09-08 19:50:58 +03:00
|
|
|
}
|
|
|
|
resource, err := s.Store.FindResource(ctx, resourceFind)
|
|
|
|
if err != nil {
|
2023-02-11 12:34:29 +03:00
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find resource by ID: %v", resourceID)).SetInternal(err)
|
2022-09-08 19:50:58 +03:00
|
|
|
}
|
|
|
|
|
2023-05-30 14:00:54 +03:00
|
|
|
// Private resource require logined user is the creator
|
|
|
|
if resourceVisibility == store.Private && (!ok || userID != resource.CreatorID) {
|
|
|
|
return echo.NewHTTPError(http.StatusUnauthorized, "Resource visibility not match").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
2023-04-16 05:31:03 +03:00
|
|
|
blob := resource.Blob
|
|
|
|
if resource.InternalPath != "" {
|
|
|
|
src, err := os.Open(resource.InternalPath)
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to open the local resource: %s", resource.InternalPath)).SetInternal(err)
|
|
|
|
}
|
|
|
|
defer src.Close()
|
|
|
|
blob, err = io.ReadAll(src)
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to read the local resource: %s", resource.InternalPath)).SetInternal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Response().Writer.Header().Set(echo.HeaderCacheControl, "max-age=31536000, immutable")
|
|
|
|
c.Response().Writer.Header().Set(echo.HeaderContentSecurityPolicy, "default-src 'self'")
|
|
|
|
resourceType := strings.ToLower(resource.Type)
|
|
|
|
if strings.HasPrefix(resourceType, "text") {
|
|
|
|
resourceType = echo.MIMETextPlainCharsetUTF8
|
|
|
|
} else if strings.HasPrefix(resourceType, "video") || strings.HasPrefix(resourceType, "audio") {
|
|
|
|
http.ServeContent(c.Response(), c.Request(), resource.Filename, time.Unix(resource.UpdatedTs, 0), bytes.NewReader(blob))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return c.Stream(http.StatusOK, resourceType, bytes.NewReader(blob))
|
|
|
|
})
|
|
|
|
|
|
|
|
g.GET("/r/:resourceId/:publicId/:filename", func(c echo.Context) error {
|
|
|
|
ctx := c.Request().Context()
|
|
|
|
resourceID, err := strconv.Atoi(c.Param("resourceId"))
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("resourceId"))).SetInternal(err)
|
|
|
|
}
|
2023-05-30 14:00:54 +03:00
|
|
|
|
|
|
|
resourceVisibility, err := CheckResourceVisibility(ctx, s.Store, resourceID)
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Failed to get resource visibility").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Protected resource require a logined user
|
|
|
|
userID, ok := c.Get(getUserIDContextKey()).(int)
|
|
|
|
if resourceVisibility == store.Protected && (!ok || userID <= 0) {
|
|
|
|
return echo.NewHTTPError(http.StatusUnauthorized, "Resource visibility not match").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
2023-04-16 05:31:03 +03:00
|
|
|
publicID, err := url.QueryUnescape(c.Param("publicId"))
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("publicID is invalid: %s", c.Param("publicId"))).SetInternal(err)
|
|
|
|
}
|
|
|
|
filename, err := url.QueryUnescape(c.Param("filename"))
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("filename is invalid: %s", c.Param("filename"))).SetInternal(err)
|
|
|
|
}
|
|
|
|
resourceFind := &api.ResourceFind{
|
|
|
|
ID: &resourceID,
|
|
|
|
PublicID: &publicID,
|
|
|
|
Filename: &filename,
|
|
|
|
GetBlob: true,
|
|
|
|
}
|
|
|
|
resource, err := s.Store.FindResource(ctx, resourceFind)
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find resource by ID: %v", resourceID)).SetInternal(err)
|
|
|
|
}
|
|
|
|
|
2023-05-30 14:00:54 +03:00
|
|
|
// Private resource require logined user is the creator
|
|
|
|
if resourceVisibility == store.Private && (!ok || userID != resource.CreatorID) {
|
|
|
|
return echo.NewHTTPError(http.StatusUnauthorized, "Resource visibility not match").SetInternal(err)
|
|
|
|
}
|
|
|
|
|
2023-03-19 14:37:57 +03:00
|
|
|
blob := resource.Blob
|
|
|
|
if resource.InternalPath != "" {
|
2023-05-15 17:42:12 +03:00
|
|
|
resourcePath := resource.InternalPath
|
|
|
|
src, err := os.Open(resourcePath)
|
2023-03-19 14:37:57 +03:00
|
|
|
if err != nil {
|
2023-05-15 17:42:12 +03:00
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to open the local resource: %s", resourcePath)).SetInternal(err)
|
2023-03-19 14:37:57 +03:00
|
|
|
}
|
|
|
|
defer src.Close()
|
|
|
|
blob, err = io.ReadAll(src)
|
|
|
|
if err != nil {
|
2023-05-15 17:42:12 +03:00
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to read the local resource: %s", resourcePath)).SetInternal(err)
|
2023-03-19 14:37:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-20 03:39:39 +03:00
|
|
|
if c.QueryParam("thumbnail") == "1" && common.HasPrefixes(resource.Type, "image/png", "image/jpeg") {
|
|
|
|
ext := filepath.Ext(filename)
|
2023-05-27 04:09:41 +03:00
|
|
|
thumbnailPath := path.Join(s.Profile.Data, thumbnailImagePath, fmt.Sprintf("%d-%s%s", resource.ID, resource.PublicID, ext))
|
2023-05-20 17:08:07 +03:00
|
|
|
thumbnailBlob, err := getOrGenerateThumbnailImage(blob, thumbnailPath)
|
2023-05-20 03:39:39 +03:00
|
|
|
if err != nil {
|
2023-05-20 17:08:07 +03:00
|
|
|
log.Warn(fmt.Sprintf("failed to get or generate local thumbnail with path %s", thumbnailPath), zap.Error(err))
|
|
|
|
} else {
|
|
|
|
blob = thumbnailBlob
|
2023-05-20 03:39:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-21 18:23:05 +03:00
|
|
|
c.Response().Writer.Header().Set(echo.HeaderCacheControl, "max-age=31536000, immutable")
|
2022-12-23 15:02:42 +03:00
|
|
|
c.Response().Writer.Header().Set(echo.HeaderContentSecurityPolicy, "default-src 'self'")
|
2023-02-11 12:34:29 +03:00
|
|
|
resourceType := strings.ToLower(resource.Type)
|
|
|
|
if strings.HasPrefix(resourceType, "text") {
|
|
|
|
resourceType = echo.MIMETextPlainCharsetUTF8
|
|
|
|
} else if strings.HasPrefix(resourceType, "video") || strings.HasPrefix(resourceType, "audio") {
|
2023-03-19 14:37:57 +03:00
|
|
|
http.ServeContent(c.Response(), c.Request(), resource.Filename, time.Unix(resource.UpdatedTs, 0), bytes.NewReader(blob))
|
2023-01-20 11:52:38 +03:00
|
|
|
return nil
|
|
|
|
}
|
2023-03-19 14:37:57 +03:00
|
|
|
return c.Stream(http.StatusOK, resourceType, bytes.NewReader(blob))
|
2022-09-08 19:50:58 +03:00
|
|
|
})
|
|
|
|
}
|
2023-01-02 18:18:12 +03:00
|
|
|
|
2023-07-02 13:56:25 +03:00
|
|
|
func (s *Server) createResourceCreateActivity(ctx context.Context, resource *api.Resource) error {
|
|
|
|
payload := apiv1.ActivityResourceCreatePayload{
|
2023-01-02 18:18:12 +03:00
|
|
|
Filename: resource.Filename,
|
|
|
|
Type: resource.Type,
|
|
|
|
Size: resource.Size,
|
|
|
|
}
|
2023-02-17 18:55:56 +03:00
|
|
|
payloadBytes, err := json.Marshal(payload)
|
2023-01-02 18:18:12 +03:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to marshal activity payload")
|
|
|
|
}
|
2023-07-02 13:56:25 +03:00
|
|
|
activity, err := s.Store.CreateActivity(ctx, &store.ActivityMessage{
|
2023-01-02 18:18:12 +03:00
|
|
|
CreatorID: resource.CreatorID,
|
2023-07-02 13:56:25 +03:00
|
|
|
Type: apiv1.ActivityResourceCreate.String(),
|
|
|
|
Level: apiv1.ActivityInfo.String(),
|
2023-02-17 18:55:56 +03:00
|
|
|
Payload: string(payloadBytes),
|
2023-01-02 18:18:12 +03:00
|
|
|
})
|
2023-01-07 06:49:58 +03:00
|
|
|
if err != nil || activity == nil {
|
|
|
|
return errors.Wrap(err, "failed to create activity")
|
|
|
|
}
|
2023-01-02 18:18:12 +03:00
|
|
|
return err
|
|
|
|
}
|
2023-03-19 14:37:57 +03:00
|
|
|
|
2023-05-23 14:15:30 +03:00
|
|
|
func replacePathTemplate(path, filename, publicID string) string {
|
2023-03-19 14:37:57 +03:00
|
|
|
t := time.Now()
|
|
|
|
path = fileKeyPattern.ReplaceAllStringFunc(path, func(s string) string {
|
|
|
|
switch s {
|
2023-05-23 14:15:30 +03:00
|
|
|
case "{publicid}":
|
|
|
|
return publicID
|
2023-03-19 14:37:57 +03:00
|
|
|
case "{filename}":
|
|
|
|
return filename
|
|
|
|
case "{timestamp}":
|
|
|
|
return fmt.Sprintf("%d", t.Unix())
|
|
|
|
case "{year}":
|
|
|
|
return fmt.Sprintf("%d", t.Year())
|
|
|
|
case "{month}":
|
|
|
|
return fmt.Sprintf("%02d", t.Month())
|
|
|
|
case "{day}":
|
|
|
|
return fmt.Sprintf("%02d", t.Day())
|
|
|
|
case "{hour}":
|
|
|
|
return fmt.Sprintf("%02d", t.Hour())
|
|
|
|
case "{minute}":
|
|
|
|
return fmt.Sprintf("%02d", t.Minute())
|
|
|
|
case "{second}":
|
|
|
|
return fmt.Sprintf("%02d", t.Second())
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
})
|
|
|
|
return path
|
|
|
|
}
|
2023-05-20 17:08:07 +03:00
|
|
|
|
2023-05-22 06:08:49 +03:00
|
|
|
var availableGeneratorAmount int32 = 32
|
2023-05-21 06:50:57 +03:00
|
|
|
|
2023-05-20 17:08:07 +03:00
|
|
|
func getOrGenerateThumbnailImage(srcBlob []byte, dstPath string) ([]byte, error) {
|
|
|
|
if _, err := os.Stat(dstPath); err != nil {
|
|
|
|
if !errors.Is(err, os.ErrNotExist) {
|
|
|
|
return nil, errors.Wrap(err, "failed to check thumbnail image stat")
|
|
|
|
}
|
|
|
|
|
2023-05-22 06:08:49 +03:00
|
|
|
if atomic.LoadInt32(&availableGeneratorAmount) <= 0 {
|
2023-05-21 06:50:57 +03:00
|
|
|
return nil, errors.New("not enough available generator amount")
|
|
|
|
}
|
2023-05-22 06:08:49 +03:00
|
|
|
atomic.AddInt32(&availableGeneratorAmount, -1)
|
2023-05-21 06:50:57 +03:00
|
|
|
defer func() {
|
2023-05-22 06:08:49 +03:00
|
|
|
atomic.AddInt32(&availableGeneratorAmount, 1)
|
2023-05-21 06:50:57 +03:00
|
|
|
}()
|
|
|
|
|
2023-05-20 17:08:07 +03:00
|
|
|
reader := bytes.NewReader(srcBlob)
|
2023-07-04 04:05:56 +03:00
|
|
|
src, err := imaging.Decode(reader, imaging.AutoOrientation(true))
|
2023-05-20 17:08:07 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to decode thumbnail image")
|
|
|
|
}
|
|
|
|
thumbnailImage := imaging.Resize(src, 512, 0, imaging.Lanczos)
|
|
|
|
|
|
|
|
dstDir := path.Dir(dstPath)
|
|
|
|
if err := os.MkdirAll(dstDir, os.ModePerm); err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to create thumbnail dir")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := imaging.Save(thumbnailImage, dstPath); err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to resize thumbnail image")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dstFile, err := os.Open(dstPath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to open the local resource")
|
|
|
|
}
|
|
|
|
defer dstFile.Close()
|
|
|
|
dstBlob, err := io.ReadAll(dstFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to read the local resource")
|
|
|
|
}
|
|
|
|
return dstBlob, nil
|
|
|
|
}
|
2023-05-30 14:00:54 +03:00
|
|
|
|
|
|
|
func CheckResourceVisibility(ctx context.Context, s *store.Store, resourceID int) (store.Visibility, error) {
|
|
|
|
memoResourceFind := &api.MemoResourceFind{
|
|
|
|
ResourceID: &resourceID,
|
|
|
|
}
|
|
|
|
|
|
|
|
memoResources, err := s.FindMemoResourceList(ctx, memoResourceFind)
|
|
|
|
if err != nil {
|
|
|
|
return store.Private, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// If resource is belongs to no memo, it'll always PRIVATE
|
|
|
|
if len(memoResources) == 0 {
|
|
|
|
return store.Private, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
memoIDs := make([]int, 0, len(memoResources))
|
|
|
|
for _, memoResource := range memoResources {
|
|
|
|
memoIDs = append(memoIDs, memoResource.MemoID)
|
|
|
|
}
|
|
|
|
visibilityList, err := s.FindMemosVisibilityList(ctx, memoIDs)
|
|
|
|
if err != nil {
|
|
|
|
return store.Private, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var isProtected bool
|
|
|
|
for _, visibility := range visibilityList {
|
|
|
|
// If any memo is PUBLIC, resource do
|
|
|
|
if visibility == store.Public {
|
|
|
|
return store.Public, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if visibility == store.Protected {
|
|
|
|
isProtected = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no memo is PUBLIC, but any memo is PROTECTED, resource do
|
|
|
|
if isProtected {
|
|
|
|
return store.Protected, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// If all memo is PRIVATE, the resource do
|
|
|
|
return store.Private, nil
|
|
|
|
}
|