Commit 4d48f508 authored by Steven's avatar Steven

chore: use resource name in frontend

parent 582cc660
...@@ -43,26 +43,22 @@ func NewService(profile *profile.Profile, store *store.Store) *Service { ...@@ -43,26 +43,22 @@ func NewService(profile *profile.Profile, store *store.Store) *Service {
} }
func (s *Service) RegisterResourcePublicRoutes(g *echo.Group) { func (s *Service) RegisterResourcePublicRoutes(g *echo.Group) {
g.GET("/r/:resourceId", s.streamResource) g.GET("/r/:resourceName", s.streamResource)
g.GET("/r/:resourceId/*", s.streamResource) g.GET("/r/:resourceName/*", s.streamResource)
} }
func (s *Service) streamResource(c echo.Context) error { func (s *Service) streamResource(c echo.Context) error {
ctx := c.Request().Context() ctx := c.Request().Context()
resourceID, err := util.ConvertStringToInt32(c.Param("resourceId")) resourceName := c.Param("resourceName")
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("resourceId"))).SetInternal(err)
}
resource, err := s.Store.GetResource(ctx, &store.FindResource{ resource, err := s.Store.GetResource(ctx, &store.FindResource{
ID: &resourceID, ResourceName: &resourceName,
GetBlob: true, GetBlob: true,
}) })
if err != nil { if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find resource by ID: %v", resourceID)).SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find resource by id: %s", resourceName)).SetInternal(err)
} }
if resource == nil { if resource == nil {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Resource not found: %d", resourceID)) return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Resource not found: %s", resourceName))
} }
// Check the related memo visibility. // Check the related memo visibility.
if resource.MemoID != nil { if resource.MemoID != nil {
......
...@@ -28,6 +28,7 @@ import ( ...@@ -28,6 +28,7 @@ import (
type Resource struct { type Resource struct {
ID int32 `json:"id"` ID int32 `json:"id"`
Name string `json:"name"`
// Standard fields // Standard fields
CreatorID int32 `json:"creatorId"` CreatorID int32 `json:"creatorId"`
...@@ -368,6 +369,7 @@ func replacePathTemplate(path, filename string) string { ...@@ -368,6 +369,7 @@ func replacePathTemplate(path, filename string) string {
func convertResourceFromStore(resource *store.Resource) *Resource { func convertResourceFromStore(resource *store.Resource) *Resource {
return &Resource{ return &Resource{
ID: resource.ID, ID: resource.ID,
Name: resource.ResourceName,
CreatorID: resource.CreatorID, CreatorID: resource.CreatorID,
CreatedTs: resource.CreatedTs, CreatedTs: resource.CreatedTs,
UpdatedTs: resource.UpdatedTs, UpdatedTs: resource.UpdatedTs,
......
...@@ -138,7 +138,7 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []* ...@@ -138,7 +138,7 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*
if resource.ExternalLink != "" { if resource.ExternalLink != "" {
enclosure.Url = resource.ExternalLink enclosure.Url = resource.ExternalLink
} else { } else {
enclosure.Url = baseURL + "/o/r/" + fmt.Sprintf("%d", resource.ID) enclosure.Url = baseURL + "/o/r/" + resource.Name
} }
enclosure.Length = strconv.Itoa(int(resource.Size)) enclosure.Length = strconv.Itoa(int(resource.Size))
enclosure.Type = resource.Type enclosure.Type = resource.Type
......
...@@ -148,6 +148,7 @@ func (s *APIV2Service) convertResourceFromStore(ctx context.Context, resource *s ...@@ -148,6 +148,7 @@ func (s *APIV2Service) convertResourceFromStore(ctx context.Context, resource *s
return &apiv2pb.Resource{ return &apiv2pb.Resource{
Id: resource.ID, Id: resource.ID,
Name: resource.ResourceName,
CreateTime: timestamppb.New(time.Unix(resource.CreatedTs, 0)), CreateTime: timestamppb.New(time.Unix(resource.CreatedTs, 0)),
Filename: resource.Filename, Filename: resource.Filename,
ExternalLink: resource.ExternalLink, ExternalLink: resource.ExternalLink,
......
...@@ -103,10 +103,10 @@ enum Visibility { ...@@ -103,10 +103,10 @@ enum Visibility {
} }
message Memo { message Memo {
// id is the unique auto-incremented id. // id is the system generated unique identifier.
int32 id = 1; int32 id = 1;
// name is the user-defined name. // name is the user provided name.
string name = 2; string name = 2;
RowStatus row_status = 3; RowStatus row_status = 3;
......
...@@ -34,13 +34,23 @@ service ResourceService { ...@@ -34,13 +34,23 @@ service ResourceService {
} }
message Resource { message Resource {
// id is the system generated unique identifier.
int32 id = 1; int32 id = 1;
google.protobuf.Timestamp create_time = 2;
string filename = 3; // name is the user provided name.
string external_link = 4; string name = 2;
string type = 5;
int64 size = 6; google.protobuf.Timestamp create_time = 3;
optional int32 memo_id = 7;
string filename = 4;
string external_link = 5;
string type = 6;
int64 size = 7;
optional int32 memo_id = 8;
} }
message CreateResourceRequest { message CreateResourceRequest {
......
...@@ -1705,7 +1705,8 @@ ...@@ -1705,7 +1705,8 @@
| Field | Type | Label | Description | | Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- | | ----- | ---- | ----- | ----------- |
| id | [int32](#int32) | | | | id | [int32](#int32) | | id is the system generated unique identifier. |
| name | [string](#string) | | name is the user provided name. |
| create_time | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | | | create_time | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | |
| filename | [string](#string) | | | | filename | [string](#string) | | |
| external_link | [string](#string) | | | | external_link | [string](#string) | | |
...@@ -2104,8 +2105,8 @@ ...@@ -2104,8 +2105,8 @@
| Field | Type | Label | Description | | Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- | | ----- | ---- | ----- | ----------- |
| id | [int32](#int32) | | id is the unique auto-incremented id. | | id | [int32](#int32) | | id is the system generated unique identifier. |
| name | [string](#string) | | name is the user-defined name. | | name | [string](#string) | | name is the user provided name. |
| row_status | [RowStatus](#memos-api-v2-RowStatus) | | | | row_status | [RowStatus](#memos-api-v2-RowStatus) | | |
| creator | [string](#string) | | The name of the creator. Format: users/{username} | | creator | [string](#string) | | The name of the creator. Format: users/{username} |
| creator_id | [int32](#int32) | | | | creator_id | [int32](#int32) | | |
......
...@@ -80,9 +80,9 @@ type Memo struct { ...@@ -80,9 +80,9 @@ type Memo struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
// id is the unique auto-incremented id. // id is the system generated unique identifier.
Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
// name is the user-defined name. // name is the user provided name.
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
RowStatus RowStatus `protobuf:"varint,3,opt,name=row_status,json=rowStatus,proto3,enum=memos.api.v2.RowStatus" json:"row_status,omitempty"` RowStatus RowStatus `protobuf:"varint,3,opt,name=row_status,json=rowStatus,proto3,enum=memos.api.v2.RowStatus" json:"row_status,omitempty"`
// The name of the creator. // The name of the creator.
......
This diff is collapsed.
...@@ -5,7 +5,7 @@ export const getResourceUrl = (resource: Resource, withOrigin = true) => { ...@@ -5,7 +5,7 @@ export const getResourceUrl = (resource: Resource, withOrigin = true) => {
return resource.externalLink; return resource.externalLink;
} }
return `${withOrigin ? window.location.origin : ""}/o/r/${resource.id}`; return `${withOrigin ? window.location.origin : ""}/o/r/${resource.name}`;
}; };
export const getResourceType = (resource: Resource) => { export const getResourceType = (resource: Resource) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment