-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added local disk as a storage * Fix for chromium version Co-authored-by: Savpek <[email protected]>
- Loading branch information
1 parent
ae967af
commit f2dfe40
Showing
7 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Pdf.Storage.Pdf.Config | ||
{ | ||
public class LocalStorageConfig | ||
{ | ||
public string Folder { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Collections.Generic; | ||
using System.IO.Abstractions; | ||
using Microsoft.Extensions.Options; | ||
using Pdf.Storage.Pdf; | ||
using Pdf.Storage.Pdf.Config; | ||
using Pdf.Storage.Pdf.PdfStores; | ||
|
||
namespace Pdf.Storage.Hangfire | ||
{ | ||
public class LocalStorage : IStorage | ||
{ | ||
private readonly IFileSystem _fileSystem; | ||
private readonly string _folder; | ||
|
||
public LocalStorage(IFileSystem fs, IOptions<LocalStorageConfig> options) | ||
{ | ||
_fileSystem = fs; | ||
|
||
_folder = options.Value.Folder ?? "/tmp/"; | ||
if (_folder[^1] != '/') | ||
_folder += "/"; | ||
} | ||
|
||
public void AddOrReplace(StorageData storageData) | ||
{ | ||
if (_fileSystem.File.Exists(GetPath(storageData.StorageFileId))) | ||
_fileSystem.File.Delete(GetPath(storageData.StorageFileId)); | ||
|
||
_fileSystem.File.WriteAllBytes(GetPath(storageData.StorageFileId), storageData.Data); | ||
} | ||
|
||
public StorageData Get(StorageFileId storageFileId) | ||
{ | ||
if (!_fileSystem.File.Exists(GetPath(storageFileId))) | ||
return null; | ||
|
||
var bytes = _fileSystem.File.ReadAllBytes(GetPath(storageFileId)); | ||
var result = new StorageData(storageFileId, bytes); | ||
|
||
return result; | ||
} | ||
|
||
public void Remove(StorageFileId storageFileId) | ||
{ | ||
if (_fileSystem.File.Exists(GetPath(storageFileId))) | ||
_fileSystem.File.Delete(GetPath(storageFileId)); | ||
} | ||
|
||
private string GetKey(StorageFileId storageFileId) | ||
{ | ||
return $"{storageFileId.Group}_{storageFileId.Id}.{storageFileId.Extension}"; | ||
} | ||
|
||
private string GetPath(StorageFileId storageFileId) | ||
{ | ||
return $"{_folder}{GetKey(storageFileId)}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters