3d2187d849
Signed-off-by: tison <wander4096@gmail.com>
76 lines
2.0 KiB
Go
76 lines
2.0 KiB
Go
/*
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
* or more contributor license agreements. See the NOTICE file
|
|
* distributed with this work for additional information
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
* to you 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 plugin
|
|
|
|
type UploadSource string
|
|
|
|
const (
|
|
UserAvatar UploadSource = "user_avatar"
|
|
UserPost UploadSource = "user_post"
|
|
AdminBranding UploadSource = "admin_branding"
|
|
)
|
|
|
|
var (
|
|
DefaultFileTypeCheckMapping = map[UploadSource]map[string]bool{
|
|
UserAvatar: {
|
|
".jpg": true,
|
|
".jpeg": true,
|
|
".png": true,
|
|
".webp": true,
|
|
},
|
|
UserPost: {
|
|
".jpg": true,
|
|
".jpeg": true,
|
|
".png": true,
|
|
".gif": true,
|
|
".webp": true,
|
|
},
|
|
AdminBranding: {
|
|
".jpg": true,
|
|
".jpeg": true,
|
|
".png": true,
|
|
".ico": true,
|
|
},
|
|
}
|
|
)
|
|
|
|
type UploadFileResponse struct {
|
|
// FullURL is the URL that can be used to access the file
|
|
FullURL string
|
|
// OriginalError is the error returned by the storage plugin. It is used for debugging.
|
|
OriginalError error
|
|
// DisplayErrorMsg is the error message that will be displayed to the user.
|
|
DisplayErrorMsg Translator
|
|
}
|
|
|
|
type Storage interface {
|
|
Base
|
|
|
|
// UploadFile uploads a file to storage.
|
|
// The file is in the Form of the ctx and the key is "file"
|
|
UploadFile(ctx *GinContext, source UploadSource) UploadFileResponse
|
|
}
|
|
|
|
var (
|
|
// CallStorage is a function that calls all registered storage
|
|
CallStorage,
|
|
registerStorage = MakePlugin[Storage](false)
|
|
)
|