Add project files.
This commit is contained in:
18
paperless-ngx-export/Models/Correspondent.cs
Normal file
18
paperless-ngx-export/Models/Correspondent.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace paperless_ngx_export.Models
|
||||
{
|
||||
public class Correspondent : ResultBase
|
||||
{
|
||||
public string slug { get; set; }
|
||||
public string name { get; set; }
|
||||
public int document_count { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
43
paperless-ngx-export/Models/CustomField.cs
Normal file
43
paperless-ngx-export/Models/CustomField.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace paperless_ngx_export.Models
|
||||
{
|
||||
public enum CustomField_DataType
|
||||
{
|
||||
select,
|
||||
date,
|
||||
@string
|
||||
}
|
||||
|
||||
public class CustomField_ExtraData
|
||||
{
|
||||
public CustomField_Select_Option[] select_options { get; set; }
|
||||
public string? default_currency { get; set; }
|
||||
}
|
||||
|
||||
public class CustomField_Select_Option
|
||||
{
|
||||
public string id { get; set; }
|
||||
public string label { get; set; }
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{label} ({id})";
|
||||
}
|
||||
}
|
||||
|
||||
public class CustomField : ResultBase
|
||||
{
|
||||
public string name { get; set; }
|
||||
public CustomField_DataType data_type { get; set; }
|
||||
public int? document_count { get; set; }
|
||||
|
||||
public CustomField_ExtraData? extra_data { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{name} ({data_type})";
|
||||
}
|
||||
}
|
||||
}
|
||||
17
paperless-ngx-export/Models/CustomFieldKeyValuePair.cs
Normal file
17
paperless-ngx-export/Models/CustomFieldKeyValuePair.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace paperless_ngx_export.Models
|
||||
{
|
||||
public class CustomFieldKeyValuePair
|
||||
{
|
||||
public int field { get; set; }
|
||||
public string value { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{field}: {value}";
|
||||
}
|
||||
}
|
||||
}
|
||||
66
paperless-ngx-export/Models/CustomFieldParsed.cs
Normal file
66
paperless-ngx-export/Models/CustomFieldParsed.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace paperless_ngx_export.Models
|
||||
{
|
||||
public class CustomFieldParsed
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public object? Value { get; set; }
|
||||
public Type DataType { get; set; }
|
||||
|
||||
public string StringValue => (string)Value;
|
||||
|
||||
public DateTime DateValue => Value != null && DataType == typeof(DateTime) ? (DateTime)Value : DateTime.MinValue;
|
||||
|
||||
public static CustomFieldParsed FromCustomFieldKeyValuePair(CustomFieldKeyValuePair pair, IEnumerable<CustomField> customFields)
|
||||
{
|
||||
if (pair.value != null && customFields.FirstOrDefault(cf => cf.Id == pair.field) is CustomField field)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (field.data_type)
|
||||
{
|
||||
case CustomField_DataType.date:
|
||||
return new CustomFieldParsed
|
||||
{
|
||||
Name = field.name,
|
||||
Value = DateTime.Parse(pair.value),
|
||||
DataType = typeof(DateTime)
|
||||
};
|
||||
break;
|
||||
case CustomField_DataType.select:
|
||||
return new CustomFieldParsed
|
||||
{
|
||||
Name = field.name,
|
||||
Value = field.extra_data.select_options.First(so => so.id == pair.value).label,
|
||||
DataType = typeof(string)
|
||||
};
|
||||
break;
|
||||
default:
|
||||
return new CustomFieldParsed
|
||||
{
|
||||
Name = field.name,
|
||||
Value = pair.value,
|
||||
DataType = typeof(string)
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Name}: {Value} ({DataType.Name})";
|
||||
}
|
||||
}
|
||||
}
|
||||
29
paperless-ngx-export/Models/Document.cs
Normal file
29
paperless-ngx-export/Models/Document.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace paperless_ngx_export.Models
|
||||
{
|
||||
public class Document : ResultBase
|
||||
{
|
||||
public int? correspondent { get; set; }
|
||||
public int? document_type { get; set; }
|
||||
public int? storage_path { get; set; }
|
||||
public string title { get; set; }
|
||||
public string content { get; set; }
|
||||
public int[] tags { get; set; }
|
||||
public DateTime created { get; set; }
|
||||
public DateTime created_date { get; set; }
|
||||
public DateTimeOffset modified { get; set; }
|
||||
public DateTimeOffset added { get; set; }
|
||||
public DateTimeOffset? deleted_at { get; set; }
|
||||
public string? archive_serial_number { get; set; }
|
||||
public string original_file_name { get; set; }
|
||||
public string archived_file_name { get; set; }
|
||||
public int owner { get; set; }
|
||||
public string[] notes { get; set; }
|
||||
public CustomFieldKeyValuePair[] custom_fields { get; set; }
|
||||
public int? page_count { get; set; }
|
||||
public string mime_type { get; set; }
|
||||
}
|
||||
}
|
||||
65
paperless-ngx-export/Models/DocumentParsed.cs
Normal file
65
paperless-ngx-export/Models/DocumentParsed.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace paperless_ngx_export.Models
|
||||
{
|
||||
public class DocumentParsed
|
||||
{
|
||||
#region static arrays
|
||||
public static Tag[] _tags { get; set; } = new Tag[0];
|
||||
public static Correspondent[] _correspondents { get; set; } = new Correspondent[0];
|
||||
public static CustomField[] _customFields { get; set; } = new CustomField[0];
|
||||
public static DocumentType[] _documentTypes { get; set; } = new DocumentType[0];
|
||||
#endregion
|
||||
|
||||
public string Correspondent { get; protected set; }
|
||||
public string DocumentType { get; protected set; } = "Unsorted";
|
||||
public string Title { get; protected set; }
|
||||
public string Content { get; protected set; }
|
||||
public List<Tag> Tags { get; protected set; } = new List<Tag>();
|
||||
public DateTime Created { get; protected set; }
|
||||
public DateTimeOffset Modified { get; protected set; }
|
||||
public DateTimeOffset Added { get; protected set; }
|
||||
public DateTimeOffset? DeletedAt { get; protected set; }
|
||||
public List<string> Notes{ get; protected set; }=new List<string>();
|
||||
public string MIMEType { get; protected set; }
|
||||
public int? PageCount { get; protected set; }
|
||||
public List<CustomFieldParsed> CustomFields { get; protected set; } = new List<CustomFieldParsed>();
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Correspondent} {DocumentType}";
|
||||
}
|
||||
|
||||
public static DocumentParsed FromDocument(Document doc)
|
||||
{
|
||||
DocumentParsed d = new DocumentParsed();
|
||||
|
||||
d.Correspondent = _correspondents.First(c => c.Id == doc.correspondent).name;
|
||||
d.DocumentType = _documentTypes.FirstOrDefault(dt => dt.Id == doc.document_type)?.name ?? "Unsorted";
|
||||
d.Title=doc.title.Trim();
|
||||
d.Content = doc.content.Trim();
|
||||
_tags.Where(_t=>doc.tags.Any(dt=>_t.Id == dt)).ToList().ForEach(t => d.Tags.Add(t));
|
||||
d.Created=doc.created;
|
||||
d.Modified=doc.modified;
|
||||
d.Added=doc.added;
|
||||
d.DeletedAt = doc.deleted_at;
|
||||
d.Notes = doc.notes.ToList(); ;
|
||||
d.MIMEType = doc.mime_type;
|
||||
d.PageCount = doc.page_count;
|
||||
_customFields.Where(_cf => doc.custom_fields.Any(dcf => _cf.Id == dcf.field)).ToList()
|
||||
.ForEach(cf =>
|
||||
{
|
||||
var cfp = CustomFieldParsed.FromCustomFieldKeyValuePair(
|
||||
doc.custom_fields.First(dcf => dcf.field == cf.Id),
|
||||
_customFields);
|
||||
if (!(cfp is null))
|
||||
{
|
||||
d.CustomFields.Add(cfp);
|
||||
}
|
||||
});
|
||||
return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
paperless-ngx-export/Models/DocumentType.cs
Normal file
18
paperless-ngx-export/Models/DocumentType.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace paperless_ngx_export.Models
|
||||
{
|
||||
public class DocumentType : ResultBase
|
||||
{
|
||||
public string slug { get; set; }
|
||||
public string name { get; set; }
|
||||
public int? document_count { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
paperless-ngx-export/Models/ResultBase.cs
Normal file
11
paperless-ngx-export/Models/ResultBase.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace paperless_ngx_export.Models
|
||||
{
|
||||
public class ResultBase
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
12
paperless-ngx-export/Models/RootObject.cs
Normal file
12
paperless-ngx-export/Models/RootObject.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace paperless_ngx_export.Models
|
||||
{
|
||||
internal class RootObject<T> where T : ResultBase
|
||||
{
|
||||
public int Count { get; set; }
|
||||
public List<T> Results { get; set; }
|
||||
}
|
||||
}
|
||||
19
paperless-ngx-export/Models/Tag.cs
Normal file
19
paperless-ngx-export/Models/Tag.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace paperless_ngx_export.Models
|
||||
{
|
||||
public class Tag : ResultBase
|
||||
{
|
||||
public string slug { get; set; }
|
||||
public string name { get; set; }
|
||||
public string color { get; set; }
|
||||
public string text_color { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{name} ({Id})";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user