Add project files.

This commit is contained in:
2026-02-21 10:30:14 -07:00
parent 398161da53
commit f662d576d1
28 changed files with 1127 additions and 0 deletions

View 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;
}
}
}

View 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})";
}
}
}

View 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}";
}
}
}

View 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})";
}
}
}

View 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; }
}
}

View 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;
}
}
}

View 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;
}
}
}

View 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; }
}
}

View 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; }
}
}

View 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})";
}
}
}