This repository has been archived by the owner on Dec 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
/
asset.go
105 lines (90 loc) · 2.88 KB
/
asset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2015-present Oursky Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package asset
import (
"io"
"time"
"github.com/skygeario/skygear-server/pkg/server/logging"
)
var log = logging.LoggerEntry("asset")
// PostFileRequest models the POST request for upload asset file
type PostFileRequest struct {
Action string `json:"action"`
ExtraFields map[string]interface{} `json:"extra-fields,omitempty"`
}
// FileRange models a byte range of a file
type FileRange struct {
From int64
To int64
}
// FileRangedGetResult models the result of getting a ranged file
type FileRangedGetResult struct {
ReadCloser io.ReadCloser
AcceptedRange FileRange
TotalSize int64
}
// FileGetter defines the interface of a getter for files
type FileGetter interface {
GetFileReader(name string) (io.ReadCloser, error)
}
// FileRangedGetter defines the interface of a getter for files supportting
// getting file within a byte range
type FileRangedGetter interface {
GetRangedFileReader(
name string,
fileRange FileRange,
) (*FileRangedGetResult, error)
}
// FilePutter defines the interface of a putter for files
type FilePutter interface {
PutFileReader(
name string,
src io.Reader,
length int64,
contentType string,
) error
}
// FilePostRequestGenerator defines the interface of a generator
// for post file request
type FilePostRequestGenerator interface {
GeneratePostFileRequest(
name string,
contentType string,
length int64,
) (*PostFileRequest, error)
}
// Store specify the interfaces of an asset store
type Store interface {
FileGetter
FilePutter
FilePostRequestGenerator
}
// URLSigner signs a signature and returns a URL accessible to that asset.
type URLSigner interface {
// SignedURL returns a url with access to the named file. If asset
// store is private, the returned URL is a signed one, allowing access
// to asset for a short period.
SignedURL(name string) (string, error)
IsSignatureRequired() bool
}
// URLSignerStore is an interface that is a union of Store and URLSigner.
//go:generate mockgen -destination=mock_asset/mock_url_signer_store.go github.com/skygeario/skygear-server/pkg/server/asset URLSignerStore
type URLSignerStore interface {
Store
URLSigner
}
// SignatureParser parses a signed signature string
type SignatureParser interface {
ParseSignature(signed string, name string, expiredAt time.Time) (valid bool, err error)
}