internal override async Task <bool> Handle(ContextAdapter context) { var metadata = context.Request.GetHeader(HeaderConstants.UploadMetadata); string fileId; DateTimeOffset?expires = null; var response = context.Response; var request = context.Request; var cancellationToken = context.CancellationToken; var tusConcatenationStore = context.Configuration.Store as ITusConcatenationStore; var uploadConcat = request.Headers.ContainsKey(HeaderConstants.UploadConcat) ? new UploadConcat(request.GetHeader(HeaderConstants.UploadConcat), context.Configuration.UrlPath) : null; var supportsUploadConcat = tusConcatenationStore != null && uploadConcat != null; var uploadLength = GetUploadLength(context.Request); if (await HandleOnBeforeCreateAsync(context, supportsUploadConcat, uploadConcat, metadata, uploadLength)) { return(true); } if (supportsUploadConcat) { fileId = await HandleCreationOfConcatFiles(context, uploadConcat, tusConcatenationStore, uploadLength, metadata, cancellationToken); } else { var creationStore = (ITusCreationStore)context.Configuration.Store; fileId = await creationStore.CreateFileAsync(uploadLength, metadata, cancellationToken); await HandleOnCreateComplete(context, fileId, supportsUploadConcat, uploadConcat, metadata, uploadLength); } ITusExpirationStore expirationStore = context.Configuration.Store as ITusExpirationStore; if (expirationStore != null && context.Configuration.Expiration != null && !(uploadConcat?.Type is FileConcatFinal)) { expires = DateTimeOffset.UtcNow.Add(context.Configuration.Expiration.Timeout); await expirationStore.SetExpirationAsync(fileId, expires.Value, context.CancellationToken); } response.SetHeader(HeaderConstants.TusResumable, HeaderConstants.TusResumableValue); response.SetHeader(HeaderConstants.Location, $"{context.Configuration.UrlPath.TrimEnd('/')}/{fileId}"); if (expires != null) { response.SetHeader(HeaderConstants.UploadExpires, expires.Value.ToString("R")); } response.SetStatus((int)HttpStatusCode.Created); return(true); }
internal async Task <DateTimeOffset?> SetExpirationIfSupported(string fileId, CancellationToken cancellationToken) { if (!_isSupported) { return(null); } var expires = DateTimeOffset.UtcNow.Add(_expiration.Timeout); await _expirationStore.SetExpirationAsync(fileId, expires, cancellationToken); return(expires); }