コード例 #1
0
        public async Task <Document> GetDocumentAsync(Project project, string documentName, string version)
        {
            var projectFolder = project.GetFileSystemPath();
            var path          = Path.Combine(projectFolder, documentName);

            CheckDirectorySecurity(projectFolder, path);
            var content = await LFileHelper.ReadAllTextAsync(path);

            var localDirectory = "";

            if (documentName.Contains("/"))
            {
                localDirectory = documentName.Substring(0, documentName.LastIndexOf('/'));
            }

            return(new Document
            {
                Content = content,
                FileName = Path.GetFileName(path),
                Format = project.Format,
                LocalDirectory = localDirectory,
                Title = documentName,
                RawRootUrl = $"/document-resources?projectId={project.Id.ToString()}&version={version}&name=",
                RootUrl = "/"
            });
        }
コード例 #2
0
        public async Task <DocumentResource> GetResource(Project project, string resourceName, string version)
        {
            var projectFolder = project.GetFileSystemPath();
            var path          = Path.Combine(projectFolder, resourceName);

            if (!LDirectoryHelper.IsSubDirectoryOf(projectFolder, path))
            {
                throw new SecurityException("Can not get a resource file out of the project folder!");
            }

            return(new DocumentResource(await LFileHelper.ReadAllBytesAsync(path)));
        }