github.com/cs3org/reva/v2@v2.27.7/internal/http/services/owncloud/ocs/handlers/cloud/capabilities/uploads.go (about)

     1  // Copyright 2018-2021 CERN
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  // In applying this license, CERN does not waive the privileges and immunities
    16  // granted to it by virtue of its status as an Intergovernmental Organization
    17  // or submit itself to any jurisdiction.
    18  
    19  package capabilities
    20  
    21  import (
    22  	"strings"
    23  
    24  	"github.com/cs3org/reva/v2/pkg/owncloud/ocs"
    25  )
    26  
    27  type chunkProtocol string
    28  
    29  var (
    30  	chunkV1  chunkProtocol = "v1"
    31  	chunkNG  chunkProtocol = "ng"
    32  	chunkTUS chunkProtocol = "tus"
    33  )
    34  
    35  func (h *Handler) getCapabilitiesForUserAgent(userAgent string) ocs.CapabilitiesData {
    36  	if userAgent != "" {
    37  		for k, v := range h.userAgentChunkingMap {
    38  			// we could also use a regexp for pattern matching
    39  			if strings.Contains(userAgent, k) {
    40  				// Creating a copy of the capabilities struct is less expensive than taking a lock
    41  				c := h.c
    42  				setCapabilitiesForChunkProtocol(chunkProtocol(v), &c)
    43  				return c
    44  			}
    45  		}
    46  	}
    47  	return h.c
    48  }
    49  
    50  func setCapabilitiesForChunkProtocol(cp chunkProtocol, c *ocs.CapabilitiesData) {
    51  	switch cp {
    52  	case chunkV1:
    53  		// 2.7+ will use Chunking V1 if "capabilities > files > bigfilechunking" is "true" AND "capabilities > dav > chunking" is not there
    54  		c.Capabilities.Files.BigFileChunking = true
    55  		c.Capabilities.Dav = nil
    56  		c.Capabilities.Files.TusSupport = nil
    57  
    58  	case chunkNG:
    59  		// 2.7+ will use Chunking NG if "capabilities > files > bigfilechunking" is "true" AND "capabilities > dav > chunking" = 1.0
    60  		c.Capabilities.Files.BigFileChunking = true
    61  		c.Capabilities.Dav.Chunking = "1.0"
    62  		c.Capabilities.Files.TusSupport = nil
    63  
    64  	case chunkTUS:
    65  		// 2.7+ will use TUS if "capabilities > files > bigfilechunking" is "false" AND "capabilities > dav > chunking" = "" AND "capabilities > files > tus_support" has proper entries.
    66  		c.Capabilities.Files.BigFileChunking = false
    67  		c.Capabilities.Dav.Chunking = ""
    68  
    69  		// TODO: infer from various TUS handlers from all known storages
    70  		// until now we take the manually configured tus options
    71  		// c.Capabilities.Files.TusSupport = &data.CapabilitiesFilesTusSupport{
    72  		// 	Version:            "1.0.0",
    73  		// 	Resumable:          "1.0.0",
    74  		// 	Extension:          "creation,creation-with-upload",
    75  		// 	MaxChunkSize:       0,
    76  		// 	HTTPMethodOverride: "",
    77  		// }
    78  	}
    79  }