add images from memos
This commit is contained in:
+39
-11
@@ -5,17 +5,45 @@ import "time"
|
||||
// Memo represents a memo from the Memos API.
|
||||
// JSON field names follow protojson camelCase convention.
|
||||
type Memo struct {
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
Creator string `json:"creator"`
|
||||
CreateTime time.Time `json:"createTime"`
|
||||
UpdateTime time.Time `json:"updateTime"`
|
||||
DisplayTime time.Time `json:"displayTime"`
|
||||
Content string `json:"content"`
|
||||
Visibility string `json:"visibility"`
|
||||
Tags []string `json:"tags"`
|
||||
Pinned bool `json:"pinned"`
|
||||
Snippet string `json:"snippet"`
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
Creator string `json:"creator"`
|
||||
CreateTime time.Time `json:"createTime"`
|
||||
UpdateTime time.Time `json:"updateTime"`
|
||||
DisplayTime time.Time `json:"displayTime"`
|
||||
Content string `json:"content"`
|
||||
Visibility string `json:"visibility"`
|
||||
Tags []string `json:"tags"`
|
||||
Pinned bool `json:"pinned"`
|
||||
Snippet string `json:"snippet"`
|
||||
Attachments []Attachment `json:"attachments"`
|
||||
}
|
||||
|
||||
// Attachment represents a file attached to a memo.
|
||||
type Attachment struct {
|
||||
Name string `json:"name"` // "attachments/{uid}"
|
||||
Filename string `json:"filename"`
|
||||
Type string `json:"type"` // MIME type
|
||||
Size int64 `json:"size,string"`
|
||||
ExternalLink string `json:"externalLink"`
|
||||
}
|
||||
|
||||
// IsImage returns true if the attachment is an image.
|
||||
func (a Attachment) IsImage() bool {
|
||||
switch a.Type {
|
||||
case "image/png", "image/jpeg", "image/gif", "image/webp", "image/heic", "image/heif", "image/svg+xml":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// UID extracts the uid part from "attachments/{uid}".
|
||||
func (a Attachment) UID() string {
|
||||
const prefix = "attachments/"
|
||||
if len(a.Name) > len(prefix) {
|
||||
return a.Name[len(prefix):]
|
||||
}
|
||||
return a.Name
|
||||
}
|
||||
|
||||
// ListMemosResponse is the response from GET /api/v1/memos.
|
||||
|
||||
Reference in New Issue
Block a user