1
0
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:
David Stotijn 2021-12-20 20:12:44 +01:00
parent a2507e3ec1
commit 50cebe29de
6 changed files with 48 additions and 68 deletions

View File

@ -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"`

View File

@ -980,8 +980,8 @@ func TestCreateDatabase(t *testing.T) {
Emoji: notion.StringPtr("✌️"), Emoji: notion.StringPtr("✌️"),
}, },
Cover: &notion.Cover{ Cover: &notion.Cover{
Type: notion.CoverTypeExternal, Type: notion.FileTypeExternal,
External: &notion.CoverExternal{ External: &notion.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: &notion.Cover{ Cover: &notion.Cover{
Type: notion.CoverTypeExternal, Type: notion.FileTypeExternal,
External: &notion.CoverExternal{ External: &notion.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: &notion.Cover{ Cover: &notion.Cover{
Type: notion.CoverTypeExternal, Type: notion.FileTypeExternal,
External: &notion.CoverExternal{ External: &notion.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: &notion.Cover{ Cover: &notion.Cover{
Type: notion.CoverTypeExternal, Type: notion.FileTypeExternal,
External: &notion.CoverExternal{ External: &notion.FileExternal{
URL: "https://example.com/image.png", URL: "https://example.com/image.png",
}, },
}, },
@ -1676,13 +1676,13 @@ func TestCreatePage(t *testing.T) {
}, },
Icon: &notion.Icon{ Icon: &notion.Icon{
Type: notion.IconTypeExternal, Type: notion.IconTypeExternal,
External: &notion.IconExternal{ External: &notion.FileExternal{
URL: "https://example.com/icon.png", URL: "https://example.com/icon.png",
}, },
}, },
Cover: &notion.Cover{ Cover: &notion.Cover{
Type: notion.CoverTypeExternal, Type: notion.FileTypeExternal,
External: &notion.CoverExternal{ External: &notion.FileExternal{
URL: "https://example.com/cover.png", URL: "https://example.com/cover.png",
}, },
}, },
@ -1809,13 +1809,13 @@ func TestCreatePage(t *testing.T) {
}, },
Icon: &notion.Icon{ Icon: &notion.Icon{
Type: notion.IconTypeExternal, Type: notion.IconTypeExternal,
External: &notion.IconExternal{ External: &notion.FileExternal{
URL: "https://example.com/icon.png", URL: "https://example.com/icon.png",
}, },
}, },
Cover: &notion.Cover{ Cover: &notion.Cover{
Type: notion.CoverTypeExternal, Type: notion.FileTypeExternal,
External: &notion.CoverExternal{ External: &notion.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: &notion.Icon{ Icon: &notion.Icon{
Type: notion.IconTypeExternal, Type: notion.IconTypeExternal,
External: &notion.IconExternal{ External: &notion.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: &notion.Icon{ Icon: &notion.Icon{
Type: notion.IconTypeExternal, Type: notion.IconTypeExternal,
External: &notion.IconExternal{ External: &notion.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: &notion.Cover{ Cover: &notion.Cover{
Type: notion.CoverTypeExternal, Type: notion.FileTypeExternal,
External: &notion.CoverExternal{ External: &notion.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: &notion.Cover{ Cover: &notion.Cover{
Type: notion.CoverTypeExternal, Type: notion.FileTypeExternal,
External: &notion.CoverExternal{ External: &notion.FileExternal{
URL: "https://example.com/image.png", URL: "https://example.com/image.png",
}, },
}, },

View File

@ -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")
} }

View File

@ -100,6 +100,10 @@ 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
View 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
View File

@ -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 {