mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-02-13 00:19:14 -06:00
FF-364 - added unzip node
This commit is contained in:
@@ -311,6 +311,18 @@
|
||||
"Body-Help": "The body of the request being sent. Variables can be used in this field."
|
||||
}
|
||||
},
|
||||
"Unzip": {
|
||||
"Description": "Allows you to unzip a file",
|
||||
"Outputs": {
|
||||
"1": "File Unzipped"
|
||||
},
|
||||
"Fields": {
|
||||
"DestinationPath": "Destination Folder",
|
||||
"DestinationPath-Help": "The destination folder where to extract the zip file.",
|
||||
"Zip": "Zip File",
|
||||
"Zip-Help": "The filename of the zip to extract. Can be left blank and if so the current working file will be used."
|
||||
}
|
||||
},,
|
||||
"Zip": {
|
||||
"Description": "Allows you to zip the input",
|
||||
"Outputs": {
|
||||
|
||||
@@ -15,41 +15,13 @@ public class OlderThan : Node
|
||||
public override string Icon => "fas fa-clock";
|
||||
public override string HelpUrl => "https://docs.fileflows.com/plugins/basic-nodes/older-than";
|
||||
|
||||
|
||||
[NumberInt(1)]
|
||||
public int Number { get; set; }
|
||||
|
||||
[NumberInt(2)]
|
||||
[Select(nameof(UnitOptions), 1)]
|
||||
public int Unit { get; set; }
|
||||
[Period(1)]
|
||||
public int Minutes { get; set; }
|
||||
|
||||
[NumberInt(3)]
|
||||
[NumberInt(2)]
|
||||
[Select(nameof(DateOptions), 1)]
|
||||
public int Date { get; set; }
|
||||
|
||||
|
||||
private static List<ListOption> _UnitOptions;
|
||||
/// <summary>
|
||||
/// Gets or sets the unit options
|
||||
/// </summary>
|
||||
public static List<ListOption> UnitOptions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_UnitOptions == null)
|
||||
{
|
||||
_UnitOptions = new List<ListOption>
|
||||
{
|
||||
new () { Label = "Minutes", Value = 1 },
|
||||
new () { Label = "Days", Value = 1440 },
|
||||
new () { Label = "Weeks", Value = 10080 }
|
||||
};
|
||||
}
|
||||
return _UnitOptions;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static List<ListOption> _DateOptions;
|
||||
/// <summary>
|
||||
/// Gets or sets the date options
|
||||
@@ -82,11 +54,7 @@ public class OlderThan : Node
|
||||
|
||||
var date = Date == 1 ? fi.LastWriteTime : fi.CreationTime;
|
||||
|
||||
// now, 1 week ago, == 7 days
|
||||
var minutes = DateTime.Now.Subtract(date).TotalMinutes;
|
||||
// 3 * 1 days, == 3 days
|
||||
var cutoff = this.Number * Math.Max(this.Unit, 1);
|
||||
// 7 > 3 == true, 1
|
||||
return minutes > cutoff ? 1 : 2;
|
||||
return minutes > this.Minutes ? 1 : 2;
|
||||
}
|
||||
}
|
||||
58
BasicNodes/Tools/Unzip.cs
Normal file
58
BasicNodes/Tools/Unzip.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using FileFlows.Plugin;
|
||||
using FileFlows.Plugin.Attributes;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace FileFlows.BasicNodes.File;
|
||||
|
||||
/// <summary>
|
||||
/// Node that unzips a file
|
||||
/// </summary>
|
||||
public class Unzip : Node
|
||||
{
|
||||
public override int Inputs => 1;
|
||||
public override int Outputs => 1;
|
||||
public override FlowElementType Type => FlowElementType.Process;
|
||||
public override string Icon => "fas fa-file-archive";
|
||||
public override string HelpUrl => "https://docs.fileflows.com/plugins/basic-nodes/unzip";
|
||||
|
||||
private string _DestinationPath = string.Empty;
|
||||
private string _zip = string.Empty;
|
||||
|
||||
[Folder(1)]
|
||||
public string DestinationPath
|
||||
{
|
||||
get => _DestinationPath;
|
||||
set { _DestinationPath = value ?? ""; }
|
||||
}
|
||||
|
||||
[TextVariable(2)]
|
||||
public string Zip
|
||||
{
|
||||
get => _zip;
|
||||
set { _zip = value ?? ""; }
|
||||
}
|
||||
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
try
|
||||
{
|
||||
var zip = args.ReplaceVariables(Zip ?? string.Empty, stripMissing: true)?.EmptyAsNull() ?? args.WorkingFile);
|
||||
|
||||
if (System.IO.File.Exists(zip) == false)
|
||||
{
|
||||
args.Logger?.ELog("File does not exist: " + zip);
|
||||
return -1;
|
||||
}
|
||||
|
||||
string destDir = args.ReplaceVariables(DestinationPath, stripMissing: true, cleanSpecialCharacters: true);
|
||||
|
||||
ZipFile.ExtractToDirectory(zip, destDir);
|
||||
return -1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
args.Logger?.ELog("Failed unzip: " + ex.Message + Environment.NewLine + ex.StackTrace);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user