public ChunkedUploaderHandlerService(
     IOptionsMonitor <ILog> optionsMonitor,
     TenantManager tenantManager,
     FileUploader fileUploader,
     FilesMessageService filesMessageService,
     AuthManager authManager,
     SecurityContext securityContext,
     SetupInfo setupInfo,
     EntryManager entryManager,
     InstanceCrypto instanceCrypto,
     ChunkedUploadSessionHolder chunkedUploadSessionHolder,
     ChunkedUploadSessionHelper chunkedUploadSessionHelper)
 {
     TenantManager              = tenantManager;
     FileUploader               = fileUploader;
     FilesMessageService        = filesMessageService;
     AuthManager                = authManager;
     SecurityContext            = securityContext;
     SetupInfo                  = setupInfo;
     EntryManager               = entryManager;
     InstanceCrypto             = instanceCrypto;
     ChunkedUploadSessionHolder = chunkedUploadSessionHolder;
     ChunkedUploadSessionHelper = chunkedUploadSessionHelper;
     Logger = optionsMonitor.CurrentValue;
 }
 /// <summary>
 /// </summary>
 /// <param name="context"></param>
 /// <param name="fileStorageService"></param>
 public FilesControllerHelper(
     ApiContext context,
     FileStorageService <T> fileStorageService,
     FileWrapperHelper fileWrapperHelper,
     FilesSettingsHelper filesSettingsHelper,
     FilesLinkUtility filesLinkUtility,
     FileUploader fileUploader,
     DocumentServiceHelper documentServiceHelper,
     TenantManager tenantManager,
     SecurityContext securityContext,
     FolderWrapperHelper folderWrapperHelper,
     FileOperationWraperHelper fileOperationWraperHelper,
     FileShareWrapperHelper fileShareWrapperHelper,
     FileShareParamsHelper fileShareParamsHelper,
     EntryManager entryManager,
     FolderContentWrapperHelper folderContentWrapperHelper,
     ChunkedUploadSessionHelper chunkedUploadSessionHelper,
     DocumentServiceTrackerHelper documentServiceTracker,
     IOptionsMonitor <ILog> optionMonitor,
     SettingsManager settingsManager,
     EncryptionKeyPairHelper encryptionKeyPairHelper,
     IHttpContextAccessor httpContextAccessor,
     FileConverter fileConverter,
     ApiDateTimeHelper apiDateTimeHelper,
     UserManager userManager,
     DisplayUserSettingsHelper displayUserSettingsHelper)
 {
     ApiContext                 = context;
     FileStorageService         = fileStorageService;
     FileWrapperHelper          = fileWrapperHelper;
     FilesSettingsHelper        = filesSettingsHelper;
     FilesLinkUtility           = filesLinkUtility;
     FileUploader               = fileUploader;
     DocumentServiceHelper      = documentServiceHelper;
     TenantManager              = tenantManager;
     SecurityContext            = securityContext;
     FolderWrapperHelper        = folderWrapperHelper;
     FileOperationWraperHelper  = fileOperationWraperHelper;
     FileShareWrapperHelper     = fileShareWrapperHelper;
     FileShareParamsHelper      = fileShareParamsHelper;
     EntryManager               = entryManager;
     FolderContentWrapperHelper = folderContentWrapperHelper;
     ChunkedUploadSessionHelper = chunkedUploadSessionHelper;
     DocumentServiceTracker     = documentServiceTracker;
     SettingsManager            = settingsManager;
     EncryptionKeyPairHelper    = encryptionKeyPairHelper;
     ApiDateTimeHelper          = apiDateTimeHelper;
     UserManager                = userManager;
     DisplayUserSettingsHelper  = displayUserSettingsHelper;
     HttpContextAccessor        = httpContextAccessor;
     FileConverter              = fileConverter;
     Logger = optionMonitor.Get("ASC.Files");
 }
        public object CreateUploadSession(T folderId, string fileName, long fileSize, string relativePath, bool encrypted)
        {
            var file = FileUploader.VerifyChunkedUpload(folderId, fileName, fileSize, FilesSettingsHelper.UpdateIfExist, relativePath);

            if (FilesLinkUtility.IsLocalFileUploader)
            {
                var session = FileUploader.InitiateUpload(file.FolderID.ToString(), (file.ID ?? default).ToString(), file.Title, file.ContentLength, encrypted);

                var response = ChunkedUploadSessionHelper.ToResponseObject(session, true);
                return(new
                {
                    success = true,
                    data = response
                });
            }

            var createSessionUrl = FilesLinkUtility.GetInitiateUploadSessionUrl(TenantManager.GetCurrentTenant().TenantId, file.FolderID, file.ID, file.Title, file.ContentLength, encrypted, SecurityContext);
            var request          = (HttpWebRequest)WebRequest.Create(createSessionUrl);

            request.Method        = "POST";
            request.ContentLength = 0;

            // hack for uploader.onlyoffice.com in api requests
            var rewriterHeader = ApiContext.HttpContext.Request.Headers[HttpRequestExtensions.UrlRewriterHeader];

            if (!string.IsNullOrEmpty(rewriterHeader))
            {
                request.Headers[HttpRequestExtensions.UrlRewriterHeader] = rewriterHeader;
            }

            // hack. http://ubuntuforums.org/showthread.php?t=1841740
            if (WorkContext.IsMono)
            {
                ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
            }

            using (var response = request.GetResponse())
                using (var responseStream = response.GetResponseStream())
                {
                    return(JObject.Parse(new StreamReader(responseStream).ReadToEnd())); //result is json string
                }
        }
        public async Task Invoke <T>(HttpContext context)
        {
            try
            {
                if (context.Request.Method == "OPTIONS")
                {
                    context.Response.StatusCode = 200;
                    return;
                }

                var request = new ChunkedRequestHelper <T>(context.Request);

                if (!TryAuthorize(request))
                {
                    await WriteError(context, "Can't authorize given initiate session request or session with specified upload id already expired");

                    return;
                }

                if (TenantManager.GetCurrentTenant().Status != TenantStatus.Active)
                {
                    await WriteError(context, "Can't perform upload for deleted or transfering portals");

                    return;
                }

                switch (request.Type(InstanceCrypto))
                {
                case ChunkedRequestType.Abort:
                    FileUploader.AbortUpload <T>(request.UploadId);
                    await WriteSuccess(context, null);

                    return;

                case ChunkedRequestType.Initiate:
                    var createdSession = FileUploader.InitiateUpload(request.FolderId, request.FileId, request.FileName, request.FileSize, request.Encrypted);
                    await WriteSuccess(context, ChunkedUploadSessionHelper.ToResponseObject(createdSession, true));

                    return;

                case ChunkedRequestType.Upload:
                    var resumedSession = FileUploader.UploadChunk <T>(request.UploadId, request.ChunkStream, request.ChunkSize);

                    if (resumedSession.BytesUploaded == resumedSession.BytesTotal)
                    {
                        await WriteSuccess(context, ToResponseObject(resumedSession.File), (int)HttpStatusCode.Created);

                        FilesMessageService.Send(resumedSession.File, MessageAction.FileUploaded, resumedSession.File.Title);
                    }
                    else
                    {
                        await WriteSuccess(context, ChunkedUploadSessionHelper.ToResponseObject(resumedSession));
                    }
                    return;

                default:
                    await WriteError(context, "Unknown request type.");

                    return;
                }
            }
            catch (FileNotFoundException error)
            {
                Logger.Error(error);
                await WriteError(context, FilesCommonResource.ErrorMassage_FileNotFound);
            }
            catch (Exception error)
            {
                Logger.Error(error);
                await WriteError(context, error.Message);
            }
        }
Beispiel #5
0
 /// <summary>
 /// </summary>
 /// <param name="context"></param>
 /// <param name="fileStorageService"></param>
 public FilesControllerHelper(
     ApiContext context,
     FileStorageService <T> fileStorageService,
     FileWrapperHelper fileWrapperHelper,
     FilesSettingsHelper filesSettingsHelper,
     FilesLinkUtility filesLinkUtility,
     FileUploader fileUploader,
     DocumentServiceHelper documentServiceHelper,
     TenantManager tenantManager,
     SecurityContext securityContext,
     FolderWrapperHelper folderWrapperHelper,
     FileOperationWraperHelper fileOperationWraperHelper,
     FileShareWrapperHelper fileShareWrapperHelper,
     FileShareParamsHelper fileShareParamsHelper,
     EntryManager entryManager,
     UserManager userManager,
     WebItemSecurity webItemSecurity,
     CoreBaseSettings coreBaseSettings,
     ThirdpartyConfiguration thirdpartyConfiguration,
     MessageService messageService,
     CommonLinkUtility commonLinkUtility,
     DocumentServiceConnector documentServiceConnector,
     FolderContentWrapperHelper folderContentWrapperHelper,
     WordpressToken wordpressToken,
     WordpressHelper wordpressHelper,
     ConsumerFactory consumerFactory,
     EasyBibHelper easyBibHelper,
     ChunkedUploadSessionHelper chunkedUploadSessionHelper,
     IOptionsMonitor <ILog> optionMonitor)
 {
     ApiContext                 = context;
     FileStorageService         = fileStorageService;
     FileWrapperHelper          = fileWrapperHelper;
     FilesSettingsHelper        = filesSettingsHelper;
     FilesLinkUtility           = filesLinkUtility;
     FileUploader               = fileUploader;
     DocumentServiceHelper      = documentServiceHelper;
     TenantManager              = tenantManager;
     SecurityContext            = securityContext;
     FolderWrapperHelper        = folderWrapperHelper;
     FileOperationWraperHelper  = fileOperationWraperHelper;
     FileShareWrapperHelper     = fileShareWrapperHelper;
     FileShareParamsHelper      = fileShareParamsHelper;
     EntryManager               = entryManager;
     UserManager                = userManager;
     WebItemSecurity            = webItemSecurity;
     CoreBaseSettings           = coreBaseSettings;
     ThirdpartyConfiguration    = thirdpartyConfiguration;
     ConsumerFactory            = consumerFactory;
     BoxLoginProvider           = ConsumerFactory.Get <BoxLoginProvider>();
     DropboxLoginProvider       = ConsumerFactory.Get <DropboxLoginProvider>();
     GoogleLoginProvider        = ConsumerFactory.Get <GoogleLoginProvider>();
     OneDriveLoginProvider      = ConsumerFactory.Get <OneDriveLoginProvider>();
     MessageService             = messageService;
     CommonLinkUtility          = commonLinkUtility;
     DocumentServiceConnector   = documentServiceConnector;
     FolderContentWrapperHelper = folderContentWrapperHelper;
     WordpressToken             = wordpressToken;
     WordpressHelper            = wordpressHelper;
     EasyBibHelper              = easyBibHelper;
     ChunkedUploadSessionHelper = chunkedUploadSessionHelper;
     Logger = optionMonitor.Get("ASC.Files");
 }