Documentation ¶
Index ¶
- Constants
- type AttachedNotesRequest
- type CheckExistenceRequest
- type CreateFromURLOptions
- type CreateRequest
- type DeleteRequest
- type FindByHashRequest
- type FindRequest
- type Service
- func (s *Service) AttachedNotes(fileID string) ([]models.Note, error)
- func (s *Service) CheckExistence(md5 string) (bool, error)
- func (s *Service) Create(request CreateRequest) (models.File, error)
- func (s *Service) CreateFromURL(options CreateFromURLOptions) (models.File, error)
- func (s *Service) Delete(fileID string) error
- func (s *Service) Find(request FindRequest) ([]models.File, error)
- func (s *Service) FindByHash(md5 string) ([]models.File, error)
- func (s *Service) Show(request ShowRequest) (models.File, error)
- func (s *Service) Update(file models.File) (models.File, error)
- func (s *Service) UploadFromURL(request UploadFromURLRequest) error
- type ShowRequest
- type UpdateRequest
- type UploadFromURLRequest
Examples ¶
Constants ¶
const RequestTimout = 30
RequestTimout is the timeout of a request in seconds.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttachedNotesRequest ¶
type AttachedNotesRequest struct {
FileID string `json:"fileId"`
}
AttachedNotesRequest list all notes where a given file has reference.
func (AttachedNotesRequest) Validate ¶
func (r AttachedNotesRequest) Validate() error
Validate the request.
type CheckExistenceRequest ¶
type CheckExistenceRequest struct {
MD5 string `json:"md5"`
}
CheckExistenceRequest is the request to check if a given file with md5 hash exists or not.
func (CheckExistenceRequest) Validate ¶
func (r CheckExistenceRequest) Validate() error
Validate the request.
type CreateFromURLOptions ¶
type CreateFromURLOptions struct { FolderID string Name string IsSensitive bool Force bool URL string DownloadClient core.HTTPClient }
CreateFromURLOptions has all the values you can play with.
type CreateRequest ¶
type CreateRequest struct { FolderID string `multipart:"folderId,type=field,omitempty"` Name string `multipart:"name,type=field"` IsSensitive bool `multipart:"isSensitive,type=field"` Force bool `multipart:"force,type=field"` Content []byte `multipart:"ref=name,type=file"` }
CreateRequest represents a request to create a file.
type DeleteRequest ¶
type DeleteRequest struct {
FileID string `json:"fileId"`
}
DeleteRequest is the request to delete a file.
type FindByHashRequest ¶
type FindByHashRequest struct {
MD5 string `json:"md5"`
}
FindByHashRequest is the request to find file(s) with md5.
func (FindByHashRequest) Validate ¶
func (r FindByHashRequest) Validate() error
Validate the request.
type FindRequest ¶
FindRequest is the request to find file(s) by their and parent folder.
type Service ¶
type Service struct {
Call core.RequestHandlerFunc
}
Service is the service for all the endpoints under /drive/files/*.
func NewService ¶
func NewService(requestHandler core.RequestHandlerFunc) *Service
NewService creates a new Service instance.
func (*Service) AttachedNotes ¶
AttachedNotes gets drive information.
Example ¶
client, _ := misskey.NewClientWithOptions(misskey.WithSimpleConfig("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))) notes, err := client.Drive().File().AttachedNotes("8a0snrdwsy") if err != nil { log.Printf("[Drive/File/AttachedNotes] %s", err) return } for _, note := range notes { log.Printf("[Drive/File/AttachedNotes] <%s> %s", note.User.Name, note.Text) }
Output:
func (*Service) CheckExistence ¶
CheckExistence check if a file exists or not with given md5. md5 hash of the file, not its name.
Example ¶
client, _ := misskey.NewClientWithOptions(misskey.WithSimpleConfig("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))) hash := "e960345a4fd3d8413ade5bf1104b1480" found, err := client.Drive().File().CheckExistence(hash) if err != nil { log.Printf("[Drive/File/CheckExistence] %s", err) return } if found { log.Printf("[Drive/File/CheckExistence] %s exists.", hash) } else { log.Printf("[Drive/File/CheckExistence] %s does not exist.", hash) }
Output:
func (*Service) Create ¶
func (s *Service) Create(request CreateRequest) (models.File, error)
Create a file.
Example ¶
client, _ := misskey.NewClientWithOptions(misskey.WithSimpleConfig("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))) fileContent := []byte{} file, err := client.Drive().File().Create(files.CreateRequest{ FolderID: "", Name: "this is the name", IsSensitive: false, Force: false, Content: fileContent, }) if err != nil { log.Printf("[Drive/File/Create] %s", err) return } log.Printf( "[Drive/File/Create] %s file uploaded. (%s)", core.StringValue(file.Name), file.ID, )
Output:
func (*Service) CreateFromURL ¶
func (s *Service) CreateFromURL(options CreateFromURLOptions) (models.File, error)
CreateFromURL downloads a file and then uploads it to the server.
It's not a Misskey endpoint. It's a pseudo endpoint.
Purpose: Replace UploadFromURL with a more convenient approach, so we can upload files from external URLs without using the async UploadFromURL. That way, we can get back a File from the request. And of course, because something stinks to me around that endpoint. Why? Check the comment on UploadFromURL.
Example ¶
client, _ := misskey.NewClientWithOptions(misskey.WithSimpleConfig("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))) file, err := client.Drive().File().CreateFromURL(files.CreateFromURLOptions{ Name: "test-filename", FolderID: "8dmwisynnu", URL: "https://www.wallpaperup.com/uploads/wallpapers/2014/01/23/235641/862478b1ad52546192af60ff03efbde9-700.jpg", //nolint:lll }) if err != nil { log.Printf("[Drive/File/CreateFromURL] %s", err) return } log.Printf("[Drive/File/CreateFromURL] %s uploaded.", core.StringValue(file.Name))
Output:
func (*Service) Delete ¶
Delete a file.
Example ¶
client, _ := misskey.NewClientWithOptions(misskey.WithSimpleConfig("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))) err := client.Drive().File().Delete("8a0snrdwsy") if err != nil { log.Printf("[Drive/File/Delete] %s", err) return }
Output:
func (*Service) Find ¶
func (s *Service) Find(request FindRequest) ([]models.File, error)
Find gets file(s) by their name and parent folder.
Example ¶
client, _ := misskey.NewClientWithOptions(misskey.WithSimpleConfig("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))) fileList, err := client.Drive().File().Find(files.FindRequest{ Name: "file-i-really-really-want.png", FolderID: core.NewString("8dmwq3bhtw"), }) if err != nil { log.Printf("[Drive/File/Find] %s", err) return } for _, file := range fileList { log.Printf( "[Drive/File/Find] %s -> %s", core.StringValue(file.FolderID), core.StringValue(file.Name), ) }
Output:
func (*Service) FindByHash ¶
FindByHash gets file(s) by their md5 hash. If there is no file with given md5 hash, it returns with an empty list without error.
Example ¶
client, _ := misskey.NewClientWithOptions(misskey.WithSimpleConfig("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))) hash := "e960345a4fd3d8413ade5bf1104b1480" fileList, err := client.Drive().File().FindByHash(hash) if err != nil { log.Printf("[Drive/File/FindByHash] %s", err) return } for _, file := range fileList { log.Printf( "[Drive/File/FindByHash] %s -> %s", core.StringValue(file.FolderID), core.StringValue(file.Name), ) }
Output:
func (*Service) Show ¶
func (s *Service) Show(request ShowRequest) (models.File, error)
Show gets a folder by its ID.
Example (ByID) ¶
client, _ := misskey.NewClientWithOptions(misskey.WithSimpleConfig("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))) file, err := client.Drive().File().Show(files.ShowRequest{ FileID: "8a0snrdwsy", }) if err != nil { log.Printf("[Drive/File/Show] %s", err) return } log.Printf( "[Drive/File/Show] <%s> %s", file.CreatedAt, core.StringValue(file.Name), )
Output:
Example (ByURL) ¶
client, _ := misskey.NewClientWithOptions(misskey.WithSimpleConfig("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))) file, err := client.Drive().File().Show(files.ShowRequest{ URL: "https://slippy.xyz/files/7387e4d8-5c44-450d-aa85-9a89a580696e", }) if err != nil { log.Printf("[Drive/File/Show] %s", err) return } log.Printf( "[Drive/File/Show] <%s> %s", file.CreatedAt, core.StringValue(file.Name), )
Output:
func (*Service) Update ¶
Update a file.
The request uses only the ID, Name and FolderID values.
Warning: Name, FolderID and the isSensitive flag (NSFW) will be updated, so if you want to change only the name, fill in the FolderID and IsSensitive value with their current value, if you leave it as null or false, it will be moved to the root of the drive and marked as SFW.
Example ¶
client, _ := misskey.NewClientWithOptions(misskey.WithSimpleConfig("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))) file, err := client.Drive().File().Show(files.ShowRequest{ FileID: "8a0snrdwsy", }) if err != nil { log.Printf("[Drive/File/Update] %s", err) return } file.FolderID = core.NewString("8dmwq3bhtw") _, err = client.Drive().File().Update(file) if err != nil { log.Printf("[Drive/File/Update] %s", err) return }
Output:
func (*Service) UploadFromURL ¶
func (s *Service) UploadFromURL(request UploadFromURLRequest) error
UploadFromURL asks the server to download an image from an external URL. As it's an asnyc request, we know nothing about the file yet, so the only response is error or nothing.
It seems the server completely ignores the Name, Comment and Marker fields. To be honest, I don't even know what Comment and Marker means, as there is no "alt text" support on images with Misskey. I think it was supported in v11 and it was never re-implemented in v12.
Advise: Use CreateFromURL instead of UploadFromURL.
Example ¶
client, _ := misskey.NewClientWithOptions(misskey.WithSimpleConfig("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))) // Just don't use this one, use CreateFromURL instead. err := client.Drive().File().UploadFromURL(files.UploadFromURLRequest{ URL: "https://www.wallpaperup.com/uploads/wallpapers/2014/01/23/235641/862478b1ad52546192af60ff03efbde9-700.jpg", //nolint:lll Name: "test-filename", IsSensitive: false, Force: false, }) if err != nil { log.Printf("[Drive/File/UploadFromURL] %s", err) return }
Output:
type ShowRequest ¶
ShowRequest is the request to show a file. FileID has higher priority, therefore if it's not empty, the endpoint will ignore the URL parameter and tries to find a file with the given ID. As a side-effect, if both of them are defined, but the FileID is different than the URL, but both exists, it will return the File with the given ID and ignores the URL parameter.
type UpdateRequest ¶
type UpdateRequest struct { FileID string `json:"fileId"` Name core.String `json:"name"` FolderID core.String `json:"folderId"` IsSensitive bool `json:"isSensitive"` }
UpdateRequest is the request object for an Update request.
type UploadFromURLRequest ¶
type UploadFromURLRequest struct { URL string `json:"url"` Name string `json:"name"` Comment core.String `json:"comment"` Marker core.String `json:"marker"` Force bool `json:"force"` IsSensitive bool `json:"isSensitive"` }
UploadFromURLRequest is the request to upload a file from a URL.
func (UploadFromURLRequest) Validate ¶
func (r UploadFromURLRequest) Validate() error
Validate the request.