2017-05-26 02:57:09 -05:00
|
|
|
// Copyright 2017 Vector Creations 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 types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
2020-12-02 11:41:00 -06:00
|
|
|
"github.com/matrix-org/dendrite/setup/config"
|
2017-05-26 02:57:09 -05:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
|
|
|
)
|
|
|
|
|
|
|
|
// FileSizeBytes is a file size in bytes
|
|
|
|
type FileSizeBytes int64
|
|
|
|
|
|
|
|
// ContentType is an HTTP Content-Type header string representing the MIME type of a request body
|
|
|
|
type ContentType string
|
|
|
|
|
|
|
|
// Filename is a string representing the name of a file
|
|
|
|
type Filename string
|
|
|
|
|
|
|
|
// Base64Hash is a base64 URLEncoding string representation of a SHA-256 hash sum
|
|
|
|
type Base64Hash string
|
|
|
|
|
|
|
|
// Path is an absolute or relative UNIX filesystem path
|
|
|
|
type Path string
|
|
|
|
|
|
|
|
// MediaID is a string representing the unique identifier for a file (could be a hash but does not have to be)
|
|
|
|
type MediaID string
|
|
|
|
|
|
|
|
// RequestMethod is an HTTP request method i.e. GET, POST, etc
|
|
|
|
type RequestMethod string
|
|
|
|
|
|
|
|
// MatrixUserID is a Matrix user ID string in the form @user:domain e.g. @alice:matrix.org
|
|
|
|
type MatrixUserID string
|
|
|
|
|
|
|
|
// MediaMetadata is metadata associated with a media file
|
|
|
|
type MediaMetadata struct {
|
2017-05-26 10:24:13 -05:00
|
|
|
MediaID MediaID
|
|
|
|
Origin gomatrixserverlib.ServerName
|
|
|
|
ContentType ContentType
|
|
|
|
FileSizeBytes FileSizeBytes
|
2022-04-14 07:32:48 -05:00
|
|
|
CreationTimestamp gomatrixserverlib.Timestamp
|
2017-05-26 10:24:13 -05:00
|
|
|
UploadName Filename
|
|
|
|
Base64Hash Base64Hash
|
|
|
|
UserID MatrixUserID
|
2017-05-26 02:57:09 -05:00
|
|
|
}
|
|
|
|
|
2017-05-31 10:56:11 -05:00
|
|
|
// RemoteRequestResult is used for broadcasting the result of a request for a remote file to routines waiting on the condition
|
|
|
|
type RemoteRequestResult struct {
|
|
|
|
// Condition used for the requester to signal the result to all other routines waiting on this condition
|
|
|
|
Cond *sync.Cond
|
2017-06-01 05:32:15 -05:00
|
|
|
// MediaMetadata of the requested file to avoid querying the database for every waiting routine
|
|
|
|
MediaMetadata *MediaMetadata
|
2017-09-19 05:40:21 -05:00
|
|
|
// An error, nil in case of no error.
|
|
|
|
Error error
|
2017-05-31 10:56:11 -05:00
|
|
|
}
|
|
|
|
|
2017-05-26 02:57:09 -05:00
|
|
|
// ActiveRemoteRequests is a lockable map of media URIs requested from remote homeservers
|
|
|
|
// It is used for ensuring multiple requests for the same file do not clobber each other.
|
|
|
|
type ActiveRemoteRequests struct {
|
|
|
|
sync.Mutex
|
|
|
|
// The string key is an mxc:// URL
|
2017-05-31 10:56:11 -05:00
|
|
|
MXCToResult map[string]*RemoteRequestResult
|
2017-05-26 02:57:09 -05:00
|
|
|
}
|
2017-06-06 18:12:49 -05:00
|
|
|
|
|
|
|
// ThumbnailSize contains a single thumbnail size configuration
|
2017-06-19 09:21:04 -05:00
|
|
|
type ThumbnailSize config.ThumbnailSize
|
2017-06-06 18:12:49 -05:00
|
|
|
|
|
|
|
// ThumbnailMetadata contains the metadata about an individual thumbnail
|
|
|
|
type ThumbnailMetadata struct {
|
|
|
|
MediaMetadata *MediaMetadata
|
|
|
|
ThumbnailSize ThumbnailSize
|
|
|
|
}
|
|
|
|
|
|
|
|
// ThumbnailGenerationResult is used for broadcasting the result of thumbnail generation to routines waiting on the condition
|
|
|
|
type ThumbnailGenerationResult struct {
|
|
|
|
// Condition used for the generator to signal the result to all other routines waiting on this condition
|
|
|
|
Cond *sync.Cond
|
|
|
|
// Resulting error from the generation attempt
|
|
|
|
Err error
|
|
|
|
}
|
|
|
|
|
|
|
|
// ActiveThumbnailGeneration is a lockable map of file paths being thumbnailed
|
|
|
|
// It is used to ensure thumbnails are only generated once.
|
|
|
|
type ActiveThumbnailGeneration struct {
|
|
|
|
sync.Mutex
|
|
|
|
// The string key is a thumbnail file path
|
|
|
|
PathToResult map[string]*ThumbnailGenerationResult
|
|
|
|
}
|
2017-09-20 09:25:25 -05:00
|
|
|
|
|
|
|
// Crop indicates we should crop the thumbnail on resize
|
|
|
|
const Crop = "crop"
|
|
|
|
|
|
|
|
// Scale indicates we should scale the thumbnail on resize
|
|
|
|
const Scale = "scale"
|