-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
478 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package notion | ||
|
||
import ( | ||
"fmt" | ||
"transfer/apis" | ||
"transfer/utils" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
Backend = new(notion) | ||
) | ||
|
||
type notion struct { | ||
apis.Backend | ||
token string | ||
pageID string | ||
resp string | ||
spaceID string | ||
Commands [][]string | ||
} | ||
|
||
func (b *notion) SetArgs(cmd *cobra.Command) { | ||
cmd.Flags().StringVarP(&b.token, "token", "t", "", "Your user cookie (token-v2)") | ||
cmd.Flags().StringVarP(&b.pageID, "page", "p", "", "Your page id") | ||
cmd.Flags().StringVarP(&b.spaceID, "space", "s", "", "Your space id") | ||
|
||
cmd.Long = fmt.Sprintf("Notion - https://notion.so/\n\n" + | ||
utils.Spacer(" Size Limit: 20M(Free), Unlimit(Pro)\n") + | ||
utils.Spacer(" Upload Service: Amazon S3 US-West\n") + | ||
utils.Spacer(" Download Service: Amazon S3 US-West, Cloudflare\n")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package notion | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"regexp" | ||
"transfer/apis" | ||
) | ||
|
||
var ( | ||
matcher = regexp.MustCompile("https://(www\\.notion\\.so/signed/https%3A%2F%2F)?s3-us-west-2\\.amazonaws\\.com.*") | ||
) | ||
|
||
func (b notion) DoDownload(link string, config apis.DownConfig) error { | ||
err := apis.DownloadFile(&apis.DownloaderConfig{ | ||
Link: link, | ||
Config: config, | ||
Modifier: apis.AddHeaders, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("download failed on %s, returns %s\n", link, err) | ||
} | ||
return nil | ||
} | ||
|
||
func (b notion) AddHeaders(req *http.Request) { | ||
req.Header.Set("User-Agent", "Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.10) "+ | ||
"Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10") | ||
req.Header.Add("accept-language", "zh-CN,zh;q=0.9,en;") | ||
req.Header.Set("User-Agent", userAgent) | ||
req.Header.Set("Accept-Language", acceptLang) | ||
req.Header.Set("cookie", fmt.Sprintf("token_v2=%v", b.token)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package notion | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/kjk/notionapi" | ||
) | ||
|
||
type uploadConfig struct { | ||
debug bool | ||
fileName string | ||
fileReader io.Reader | ||
fileSize int64 | ||
} | ||
|
||
// POST /api/v3/getUploadFileUrl request | ||
type getUploadFileUrlRequest struct { | ||
Bucket string `json:"bucket"` | ||
ContentType string `json:"contentType"` | ||
Name string `json:"name"` | ||
} | ||
|
||
// GetUploadFileUrlResponse is a response to POST /api/v3/getUploadFileUrl | ||
type GetUploadFileUrlResponse struct { | ||
URL string `json:"url"` | ||
SignedGetURL string `json:"signedGetUrl"` | ||
SignedPutURL string `json:"signedPutUrl"` | ||
|
||
FileID string `json:"-"` | ||
|
||
RawJSON map[string]interface{} `json:"-"` | ||
} | ||
|
||
type Client struct { | ||
notionapi.Client | ||
} | ||
|
||
type submitTransactionRequest struct { | ||
RequestID string `json:"requestId"` | ||
Transaction []Transaction `json:"transactions"` | ||
} | ||
|
||
type Transaction struct { | ||
ID string `json:"id"` | ||
SpaceID string `json:"spaceId"` | ||
Operations []*Operation `json:"operations"` | ||
} | ||
|
||
type Operation struct { | ||
Point Pointer `json:"pointer"` | ||
Path []string `json:"path"` | ||
Command string `json:"command"` | ||
Args interface{} `json:"args"` | ||
} | ||
|
||
type Pointer struct { | ||
ID string `json:"id"` | ||
Table string `json:"table"` | ||
} |
Oops, something went wrong.