mirror of
https://github.com/dstotijn/go-notion.git
synced 2025-06-06 23:36:14 +02:00
Add file metadata to file
DB page prop
This commit is contained in:
parent
a2507e3ec1
commit
50cebe29de
16
block.go
16
block.go
@ -91,22 +91,6 @@ type FileBlock struct {
|
|||||||
Caption []RichText `json:"caption,omitempty"`
|
Caption []RichText `json:"caption,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FileFile struct {
|
|
||||||
URL string `json:"url"`
|
|
||||||
ExpiryTime DateTime `json:"expiry_time"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type FileExternal struct {
|
|
||||||
URL string `json:"url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type FileType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
FileTypeFile FileType = "file"
|
|
||||||
FileTypeExternal FileType = "external"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Bookmark struct {
|
type Bookmark struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Caption []RichText `json:"caption,omitempty"`
|
Caption []RichText `json:"caption,omitempty"`
|
||||||
|
@ -980,8 +980,8 @@ func TestCreateDatabase(t *testing.T) {
|
|||||||
Emoji: notion.StringPtr("✌️"),
|
Emoji: notion.StringPtr("✌️"),
|
||||||
},
|
},
|
||||||
Cover: ¬ion.Cover{
|
Cover: ¬ion.Cover{
|
||||||
Type: notion.CoverTypeExternal,
|
Type: notion.FileTypeExternal,
|
||||||
External: ¬ion.CoverExternal{
|
External: ¬ion.FileExternal{
|
||||||
URL: "https://example.com/image.png",
|
URL: "https://example.com/image.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1098,8 +1098,8 @@ func TestCreateDatabase(t *testing.T) {
|
|||||||
Emoji: notion.StringPtr("✌️"),
|
Emoji: notion.StringPtr("✌️"),
|
||||||
},
|
},
|
||||||
Cover: ¬ion.Cover{
|
Cover: ¬ion.Cover{
|
||||||
Type: notion.CoverTypeExternal,
|
Type: notion.FileTypeExternal,
|
||||||
External: ¬ion.CoverExternal{
|
External: ¬ion.FileExternal{
|
||||||
URL: "https://example.com/image.png",
|
URL: "https://example.com/image.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1264,8 +1264,8 @@ func TestUpdateDatabase(t *testing.T) {
|
|||||||
Emoji: notion.StringPtr("✌️"),
|
Emoji: notion.StringPtr("✌️"),
|
||||||
},
|
},
|
||||||
Cover: ¬ion.Cover{
|
Cover: ¬ion.Cover{
|
||||||
Type: notion.CoverTypeExternal,
|
Type: notion.FileTypeExternal,
|
||||||
External: ¬ion.CoverExternal{
|
External: ¬ion.FileExternal{
|
||||||
URL: "https://example.com/image.png",
|
URL: "https://example.com/image.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1388,8 +1388,8 @@ func TestUpdateDatabase(t *testing.T) {
|
|||||||
Emoji: notion.StringPtr("✌️"),
|
Emoji: notion.StringPtr("✌️"),
|
||||||
},
|
},
|
||||||
Cover: ¬ion.Cover{
|
Cover: ¬ion.Cover{
|
||||||
Type: notion.CoverTypeExternal,
|
Type: notion.FileTypeExternal,
|
||||||
External: ¬ion.CoverExternal{
|
External: ¬ion.FileExternal{
|
||||||
URL: "https://example.com/image.png",
|
URL: "https://example.com/image.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1676,13 +1676,13 @@ func TestCreatePage(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Icon: ¬ion.Icon{
|
Icon: ¬ion.Icon{
|
||||||
Type: notion.IconTypeExternal,
|
Type: notion.IconTypeExternal,
|
||||||
External: ¬ion.IconExternal{
|
External: ¬ion.FileExternal{
|
||||||
URL: "https://example.com/icon.png",
|
URL: "https://example.com/icon.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Cover: ¬ion.Cover{
|
Cover: ¬ion.Cover{
|
||||||
Type: notion.CoverTypeExternal,
|
Type: notion.FileTypeExternal,
|
||||||
External: ¬ion.CoverExternal{
|
External: ¬ion.FileExternal{
|
||||||
URL: "https://example.com/cover.png",
|
URL: "https://example.com/cover.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1809,13 +1809,13 @@ func TestCreatePage(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Icon: ¬ion.Icon{
|
Icon: ¬ion.Icon{
|
||||||
Type: notion.IconTypeExternal,
|
Type: notion.IconTypeExternal,
|
||||||
External: ¬ion.IconExternal{
|
External: ¬ion.FileExternal{
|
||||||
URL: "https://example.com/icon.png",
|
URL: "https://example.com/icon.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Cover: ¬ion.Cover{
|
Cover: ¬ion.Cover{
|
||||||
Type: notion.CoverTypeExternal,
|
Type: notion.FileTypeExternal,
|
||||||
External: ¬ion.CoverExternal{
|
External: ¬ion.FileExternal{
|
||||||
URL: "https://example.com/cover.png",
|
URL: "https://example.com/cover.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -2204,7 +2204,7 @@ func TestUpdatePageProps(t *testing.T) {
|
|||||||
params: notion.UpdatePageParams{
|
params: notion.UpdatePageParams{
|
||||||
Icon: ¬ion.Icon{
|
Icon: ¬ion.Icon{
|
||||||
Type: notion.IconTypeExternal,
|
Type: notion.IconTypeExternal,
|
||||||
External: ¬ion.IconExternal{
|
External: ¬ion.FileExternal{
|
||||||
URL: "https://www.notion.so/front-static/pages/pricing/pro.png",
|
URL: "https://www.notion.so/front-static/pages/pricing/pro.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -2276,7 +2276,7 @@ func TestUpdatePageProps(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Icon: ¬ion.Icon{
|
Icon: ¬ion.Icon{
|
||||||
Type: notion.IconTypeExternal,
|
Type: notion.IconTypeExternal,
|
||||||
External: ¬ion.IconExternal{
|
External: ¬ion.FileExternal{
|
||||||
URL: "https://www.notion.so/front-static/pages/pricing/pro.png",
|
URL: "https://www.notion.so/front-static/pages/pricing/pro.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -2303,8 +2303,8 @@ func TestUpdatePageProps(t *testing.T) {
|
|||||||
name: "page cover, successful response",
|
name: "page cover, successful response",
|
||||||
params: notion.UpdatePageParams{
|
params: notion.UpdatePageParams{
|
||||||
Cover: ¬ion.Cover{
|
Cover: ¬ion.Cover{
|
||||||
Type: notion.CoverTypeExternal,
|
Type: notion.FileTypeExternal,
|
||||||
External: ¬ion.CoverExternal{
|
External: ¬ion.FileExternal{
|
||||||
URL: "https://example.com/image.png",
|
URL: "https://example.com/image.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -2375,8 +2375,8 @@ func TestUpdatePageProps(t *testing.T) {
|
|||||||
PageID: "b0668f48-8d66-4733-9bdb-2f82215707f7",
|
PageID: "b0668f48-8d66-4733-9bdb-2f82215707f7",
|
||||||
},
|
},
|
||||||
Cover: ¬ion.Cover{
|
Cover: ¬ion.Cover{
|
||||||
Type: notion.CoverTypeExternal,
|
Type: notion.FileTypeExternal,
|
||||||
External: ¬ion.CoverExternal{
|
External: ¬ion.FileExternal{
|
||||||
URL: "https://example.com/image.png",
|
URL: "https://example.com/image.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
24
cover.go
24
cover.go
@ -2,27 +2,11 @@ package notion
|
|||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
type CoverType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
CoverTypeFile CoverType = "file"
|
|
||||||
CoverTypeExternal CoverType = "external"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Cover struct {
|
type Cover struct {
|
||||||
Type CoverType `json:"type"`
|
Type FileType `json:"type"`
|
||||||
|
|
||||||
File *CoverFile `json:"file,omitempty"`
|
File *FileFile `json:"file,omitempty"`
|
||||||
External *CoverExternal `json:"external,omitempty"`
|
External *FileExternal `json:"external,omitempty"`
|
||||||
}
|
|
||||||
|
|
||||||
type CoverFile struct {
|
|
||||||
URL string `json:"url"`
|
|
||||||
ExpiryTime DateTime `json:"expiry_time"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CoverExternal struct {
|
|
||||||
URL string `json:"url"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cover Cover) Validate() error {
|
func (cover Cover) Validate() error {
|
||||||
@ -30,7 +14,7 @@ func (cover Cover) Validate() error {
|
|||||||
return errors.New("cover type cannot be empty")
|
return errors.New("cover type cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
if cover.Type == CoverTypeExternal && cover.External == nil {
|
if cover.Type == FileTypeExternal && cover.External == nil {
|
||||||
return errors.New("cover external cannot be empty")
|
return errors.New("cover external cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,11 @@ type People struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Type FileType `json:"type"`
|
||||||
|
|
||||||
|
File *FileFile `json:"file,omitempty"`
|
||||||
|
External *FileExternal `json:"external,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DatabaseProperty struct {
|
type DatabaseProperty struct {
|
||||||
|
17
file.go
Normal file
17
file.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package notion
|
||||||
|
|
||||||
|
type FileFile struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
ExpiryTime DateTime `json:"expiry_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type FileExternal struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type FileType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
FileTypeFile FileType = "file"
|
||||||
|
FileTypeExternal FileType = "external"
|
||||||
|
)
|
13
icon.go
13
icon.go
@ -16,17 +16,8 @@ type Icon struct {
|
|||||||
Type IconType `json:"type"`
|
Type IconType `json:"type"`
|
||||||
|
|
||||||
Emoji *string `json:"emoji,omitempty"`
|
Emoji *string `json:"emoji,omitempty"`
|
||||||
File *IconFile `json:"file,omitempty"`
|
File *FileFile `json:"file,omitempty"`
|
||||||
External *IconExternal `json:"external,omitempty"`
|
External *FileExternal `json:"external,omitempty"`
|
||||||
}
|
|
||||||
|
|
||||||
type IconFile struct {
|
|
||||||
URL string `json:"url"`
|
|
||||||
ExpiryTime DateTime `json:"expiry_time"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type IconExternal struct {
|
|
||||||
URL string `json:"url"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (icon Icon) Validate() error {
|
func (icon Icon) Validate() error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user