예제 #1
0
        public async Task <IActionResult> CloneFile([FromRoute] string path)
        {
            var user = await GetCurrentUserAsync();

            await _filesService.CopyFileAsync(await _accesstoken, user.SiteName, path, user.SiteName, path.DetachPath());

            return(RedirectToAction(nameof(ViewFiles), new { path = path.DetachPath() }));
        }
예제 #2
0
        public async Task <IActionResult> ForwardMedia(ForwardMediaAddressModel model)
        {
            var user = await GetKahlaUser();

            var sourceConversation = await _dbContext
                                     .Conversations
                                     .Include(nameof(GroupConversation.Users))
                                     .SingleOrDefaultAsync(t => t.Id == model.SourceConversationId);

            var targetConversation = await _dbContext
                                     .Conversations
                                     .Include(nameof(GroupConversation.Users))
                                     .SingleOrDefaultAsync(t => t.Id == model.TargetConversationId);

            if (sourceConversation == null)
            {
                return(this.Protocol(ErrorType.NotFound, $"Could not find the source conversation with id: {model.SourceConversationId}!"));
            }
            if (targetConversation == null)
            {
                return(this.Protocol(ErrorType.NotFound, $"Could not find the target conversation with id: {model.TargetConversationId}!"));
            }
            if (!sourceConversation.HasUser(user.Id))
            {
                return(this.Protocol(ErrorType.Unauthorized, $"You are not authorized to access file from conversation: {sourceConversation.Id}!"));
            }
            if (!targetConversation.HasUser(user.Id))
            {
                return(this.Protocol(ErrorType.Unauthorized, $"You are not authorized to access file from conversation: {targetConversation.Id}!"));
            }
            var accessToken = await _appsContainer.AccessToken();

            var siteName = _configuration["UserFilesSiteName"];
            var response = await _probeFileService.CopyFileAsync(
                accessToken : accessToken,
                siteName : siteName,
                folderNames : $"conversation-{sourceConversation.Id}/{model.SourceFilePath}",
                targetSiteName : siteName,
                targetFolderNames : $"conversation-{targetConversation.Id}/{DateTime.UtcNow:yyyy-MM-dd}");

            return(Json(response));
        }