Skip to content

Commit

Permalink
feat: Implement Admin/Drive
Browse files Browse the repository at this point in the history
Closes #61
  • Loading branch information
yitsushi committed Mar 19, 2022
1 parent 8c92f41 commit da53e01
Show file tree
Hide file tree
Showing 15 changed files with 659 additions and 6 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ Check the `docs` directory for more information.
| :white_check_mark: | [clips](https://misskey.io/api-doc#tag/clips) | [#8](https://github.com/yitsushi/go-misskey/issues/8) ||
| :white_check_mark: | [drive](https://misskey.io/api-doc#tag/drive) | [#9](https://github.com/yitsushi/go-misskey/issues/9) ||
| :white_check_mark: | [following](https://misskey.io/api-doc#tag/following) | [#10](https://github.com/yitsushi/go-misskey/issues/10) ||
| :x: | [games](https://misskey.io/api-doc#tag/games) | [#11](https://github.com/yitsushi/go-misskey/issues/11) ||
| :white_check_mark: | [hashtags](https://misskey.io/api-doc#tag/hashtags) | [#12](https://github.com/yitsushi/go-misskey/issues/12) ||
| :x: | [messaging](https://misskey.io/api-doc#tag/messaging) | [#13](https://github.com/yitsushi/go-misskey/issues/13) ||
| :white_check_mark: | [reactions](https://misskey.io/api-doc#tag/reactions) | [#14](https://github.com/yitsushi/go-misskey/issues/14) ||
| :white_check_mark: | [notifications](https://misskey.io/api-doc#tag/notifications) | [#15](https://github.com/yitsushi/go-misskey/issues/15) ||
| :x: | [pages](https://misskey.io/api-doc#tag/pages) | [#16](https://github.com/yitsushi/go-misskey/issues/16) ||
| :x: | [users](https://misskey.io/api-doc#tag/users) | [#17](https://github.com/yitsushi/go-misskey/issues/17) ||
| :x: | [room](https://misskey.io/api-doc#tag/room) | [#18](https://github.com/yitsushi/go-misskey/issues/18) ||
| :x: | [groups](https://misskey.io/api-doc#tag/groups) | [#19](https://github.com/yitsushi/go-misskey/issues/19) ||
| :x: | [list](https://misskey.io/api-doc#tag/lists) | [#20](https://github.com/yitsushi/go-misskey/issues/20) ||

Expand Down
11 changes: 7 additions & 4 deletions models/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ type File struct {
Blurhash string `json:"blurhash"`
Properties FileProperties `json:"properties"`
URL string `json:"url"`
Comment string `json:"comment"`
ThumbnailURL string `json:"thumbnailUrl"`
FolderID core.String `json:"folderId"`
Folder interface{} `json:"folder"`
User interface{} `json:"user"`
Folder *Folder `json:"folder"`
User *User `json:"user"`
}

// FileProperties holds the properties of the file like width and height.
// I don't know if there are other too, so I'll go that way now.
type FileProperties struct {
Width int `json:"width"`
Height int `json:"height"`
Width int `json:"width"`
Height int `json:"height"`
Orientation int `json:"orientation"`
AvgColor string `json:"avgColor"`
}
23 changes: 23 additions & 0 deletions services/admin/drive/clean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package drive

import (
"github.com/yitsushi/go-misskey/core"
)

// CleanRequest represents a Clean request.
type CleanRequest struct{}

// Validate the request.
func (r CleanRequest) Validate() error {
return nil
}

// Clean local drive.
func (s *Service) Clean() error {
err := s.Call(
&core.JSONRequest{Request: &CleanRequest{}, Path: "/admin/drive/cleanup"},
&core.EmptyResponse{},
)

return err
}
23 changes: 23 additions & 0 deletions services/admin/drive/clean_remote.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package drive

import (
"github.com/yitsushi/go-misskey/core"
)

// CleanRemoteRequest represents a CleanRemote request.
type CleanRemoteRequest struct{}

// Validate the request.
func (r CleanRemoteRequest) Validate() error {
return nil
}

// CleanRemote drive.
func (s *Service) CleanRemote() error {
err := s.Call(
&core.JSONRequest{Request: &CleanRemoteRequest{}, Path: "/admin/drive/clean-remote-files"},
&core.EmptyResponse{},
)

return err
}
50 changes: 50 additions & 0 deletions services/admin/drive/clean_remote_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package drive_test

import (
"log"
"net/http"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/yitsushi/go-misskey"
"github.com/yitsushi/go-misskey/core"
"github.com/yitsushi/go-misskey/services/admin/drive"
"github.com/yitsushi/go-misskey/test"
)

func TestService_CleanRemote(t *testing.T) {
client := test.MakeMockClient(test.SimpleMockOptions{
Endpoint: "/api/admin/drive/clean-remote-files",
RequestData: &drive.CleanRemoteRequest{},
ResponseFile: "empty",
StatusCode: http.StatusNoContent,
})

err := client.Admin().Drive().CleanRemote()

if !assert.NoError(t, err) {
return
}
}

func TestCleanRemoteRequest_Validate(t *testing.T) {
test.ValidateRequests(
t,
[]core.BaseRequest{},
[]core.BaseRequest{
drive.CleanRemoteRequest{},
},
)
}

func ExampleService_CleanRemote() {
client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))

err := client.Admin().Drive().CleanRemote()
if err != nil {
log.Printf("[Admin/Drive/CleanRemote] %s", err)

return
}
}
50 changes: 50 additions & 0 deletions services/admin/drive/clean_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package drive_test

import (
"log"
"net/http"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/yitsushi/go-misskey"
"github.com/yitsushi/go-misskey/core"
"github.com/yitsushi/go-misskey/services/admin/drive"
"github.com/yitsushi/go-misskey/test"
)

func TestService_Clean(t *testing.T) {
client := test.MakeMockClient(test.SimpleMockOptions{
Endpoint: "/api/admin/drive/cleanup",
RequestData: &drive.CleanRequest{},
ResponseFile: "empty",
StatusCode: http.StatusNoContent,
})

err := client.Admin().Drive().Clean()

if !assert.NoError(t, err) {
return
}
}

func TestCleanRequest_Validate(t *testing.T) {
test.ValidateRequests(
t,
[]core.BaseRequest{},
[]core.BaseRequest{
drive.CleanRequest{},
},
)
}

func ExampleService_Clean() {
client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))

err := client.Admin().Drive().Clean()
if err != nil {
log.Printf("[Admin/Drive/Clean] %s", err)

return
}
}
33 changes: 33 additions & 0 deletions services/admin/drive/files.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package drive

import (
"github.com/yitsushi/go-misskey/core"
"github.com/yitsushi/go-misskey/models"
)

// FilesRequest represents a Files request.
type FilesRequest struct {
Limit uint `json:"limit,omitempty"`
SinceID string `json:"sinceId,omitempty"`
UntilID string `json:"untilId,omitempty"`
Type core.String `json:"type,omitempty"`
Origin models.UserOrigin `json:"origin,omitempty"`
Hostname core.String `json:"hostname,omitempty"`
}

// Validate the request.
func (r FilesRequest) Validate() error {
return nil
}

// Files lists all emojies.
func (s *Service) Files(request FilesRequest) ([]models.File, error) {
var response []models.File

err := s.Call(
&core.JSONRequest{Request: &request, Path: "/admin/drive/files"},
&response,
)

return response, err
}
56 changes: 56 additions & 0 deletions services/admin/drive/files_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package drive_test

import (
"log"
"net/http"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/yitsushi/go-misskey"
"github.com/yitsushi/go-misskey/core"
"github.com/yitsushi/go-misskey/services/admin/drive"
"github.com/yitsushi/go-misskey/test"
)

func TestService_Files(t *testing.T) {
client := test.MakeMockClient(test.SimpleMockOptions{
Endpoint: "/api/admin/drive/files",
RequestData: &drive.FilesRequest{},
ResponseFile: "files.json",
StatusCode: http.StatusOK,
})

response, err := client.Admin().Drive().Files(drive.FilesRequest{})

if !assert.NoError(t, err) {
return
}

assert.Len(t, response, 10)
}

func TestFilesRequest_Validate(t *testing.T) {
test.ValidateRequests(
t,
[]core.BaseRequest{},
[]core.BaseRequest{
drive.FilesRequest{},
},
)
}

func ExampleService_Files() {
client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))

response, err := client.Admin().Drive().Files(drive.FilesRequest{})
if err != nil {
log.Printf("[Admin/Drive/Files] %s", err)

return
}

for _, item := range response {
log.Printf("[Admin/Drive/Files] %s", item.URL)
}
}
Empty file.
29 changes: 29 additions & 0 deletions services/admin/drive/fixtures/file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"accessKey": "c68244ab-7edf-489f-a8b2-f476e6b9e165",
"blurhash": "y9E.^YsC4Ti_00?vEL00-p_3xu~q4.o}^+MxIUM{xu%MIU-;ofNGtRIUV@xa4.tR?bWBn%njniE1E14.oJ%Mxuxb%gR+fkIUM{xu%M",
"comment": null,
"createdAt": "2022-03-19T18:54:24.968Z",
"folderId": null,
"id": "8y1rwxxkk9",
"isLink": false,
"isSensitive": false,
"md5": "f1da991de57f451d7649a22026a5a15a",
"name": "d4391807-0d94-4888-ac34-b23a040ac620",
"properties": {
"height": 112,
"width": 112
},
"size": 9489,
"src": "https://ente.fun/files/d4391807-0d94-4888-ac34-b23a040ac620",
"storedInternal": true,
"thumbnailAccessKey": "thumbnail-89d0d4ac-f755-4fe0-b82d-de69f3ab27ea",
"thumbnailUrl": "https://slippy.xyz/files/thumbnail-89d0d4ac-f755-4fe0-b82d-de69f3ab27ea",
"type": "image/png",
"uri": null,
"url": "https://slippy.xyz/files/c68244ab-7edf-489f-a8b2-f476e6b9e165",
"userHost": null,
"userId": null,
"webpublicAccessKey": "webpublic-4eab0892-9dc0-4730-83e0-0e65642242ce",
"webpublicType": "image/png",
"webpublicUrl": "https://slippy.xyz/files/webpublic-4eab0892-9dc0-4730-83e0-0e65642242ce"
}
Loading

0 comments on commit da53e01

Please sign in to comment.