Ejemplo n.º 1
0
        internal override async Task <bool> Handle(ContextAdapter context)
        {
            var response          = context.Response;
            var cancellationToken = context.CancellationToken;
            var store             = context.Configuration.Store;

            var fileId = context.GetFileId();

            response.SetHeader(HeaderConstants.TusResumable, HeaderConstants.TusResumableValue);
            response.SetHeader(HeaderConstants.CacheControl, HeaderConstants.NoStore);

            await AddUploadMetadata(context, fileId, cancellationToken);

            var uploadLength = await store.GetUploadLengthAsync(fileId, cancellationToken);

            AddUploadLength(context, uploadLength);

            var uploadOffset = await store.GetUploadOffsetAsync(fileId, cancellationToken);

            FileConcat uploadConcat    = null;
            var        addUploadOffset = true;

            if (context.Configuration.Store is ITusConcatenationStore tusConcatStore)
            {
                uploadConcat = await tusConcatStore.GetUploadConcatAsync(fileId, cancellationToken);

                // Only add Upload-Offset to final files if they are complete.
                if (uploadConcat is FileConcatFinal && uploadLength != uploadOffset)
                {
                    addUploadOffset = false;
                }
            }

            if (addUploadOffset)
            {
                response.SetHeader(HeaderConstants.UploadOffset, uploadOffset.ToString());
            }

            if (uploadConcat != null)
            {
                (uploadConcat as FileConcatFinal)?.AddUrlPathToFiles(context.Configuration.UrlPath);
                response.SetHeader(HeaderConstants.UploadConcat, uploadConcat.GetHeader());
            }

            return(true);
        }
Ejemplo n.º 2
0
        internal override async Task Invoke()
        {
            Response.SetHeader(HeaderConstants.TusResumable, HeaderConstants.TusResumableValue);
            Response.SetHeader(HeaderConstants.CacheControl, HeaderConstants.NoStore);

            var uploadMetadata = await GetMetadata(Context);

            if (!string.IsNullOrEmpty(uploadMetadata))
            {
                Response.SetHeader(HeaderConstants.UploadMetadata, uploadMetadata);
            }

            var uploadLength = await Store.GetUploadLengthAsync(Request.FileId, CancellationToken);

            SetUploadLengthHeader(Context, uploadLength);

            var uploadOffset = await Store.GetUploadOffsetAsync(Request.FileId, CancellationToken);

            FileConcat uploadConcat    = null;
            var        addUploadOffset = true;

            if (Context.Configuration.Store is ITusConcatenationStore tusConcatStore)
            {
                uploadConcat = await tusConcatStore.GetUploadConcatAsync(Request.FileId, CancellationToken);

                // Only add Upload-Offset to final files if they are complete.
                if (uploadConcat is FileConcatFinal && uploadLength != uploadOffset)
                {
                    addUploadOffset = false;
                }
            }

            if (addUploadOffset)
            {
                Response.SetHeader(HeaderConstants.UploadOffset, uploadOffset.ToString());
            }

            if (uploadConcat != null)
            {
                (uploadConcat as FileConcatFinal)?.AddUrlPathToFiles(Context.Configuration.UrlPath);
                Response.SetHeader(HeaderConstants.UploadConcat, uploadConcat.GetHeader());
            }
        }