| | | 1 | | using System.Collections.ObjectModel; |
| | | 2 | | |
| | | 3 | | namespace Kestrun.Forms; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Represents a parsed form payload. |
| | | 7 | | /// </summary> |
| | | 8 | | public interface IKrFormPayload { } |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Represents a form payload containing named fields and files. |
| | | 12 | | /// </summary> |
| | | 13 | | [OpenApiSchemaComponent( |
| | | 14 | | Description = "Base schema for parsed multipart/form-data payloads. Concrete form models should declare the expected |
| | | 15 | | Type = OaSchemaType.Object, |
| | | 16 | | AdditionalPropertiesAllowed = true, AdditionalProperties = typeof(string) |
| | | 17 | | )] |
| | | 18 | | public class KrFormData : IKrFormPayload |
| | | 19 | | { |
| | | 20 | | /// <summary> |
| | | 21 | | /// Gets the parsed fields keyed by field name. |
| | | 22 | | /// </summary> |
| | | 23 | | public Dictionary<string, string[]> Fields { get; } = new(StringComparer.OrdinalIgnoreCase); |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Gets the parsed files keyed by field name. |
| | | 27 | | /// </summary> |
| | | 28 | | public Dictionary<string, KrFilePart[]> Files { get; } = new(StringComparer.OrdinalIgnoreCase); |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Represents a form payload containing ordered parts. |
| | | 33 | | /// </summary> |
| | | 34 | | [OpenApiSchemaComponent( |
| | | 35 | | Description = "Base schema for parsed multipart/mixed payloads. Concrete models should declare the expected parts as |
| | | 36 | | Type = OaSchemaType.Object, |
| | | 37 | | AdditionalPropertiesAllowed = true |
| | | 38 | | )] |
| | | 39 | | public class KrMultipart : IKrFormPayload |
| | | 40 | | { |
| | | 41 | | /// <summary> |
| | | 42 | | /// Gets the ordered list of parts in the payload. |
| | | 43 | | /// </summary> |
| | | 44 | | public List<KrRawPart> Parts { get; } = []; |
| | | 45 | | } |
| | | 46 | | |
| | | 47 | | /// <summary> |
| | | 48 | | /// Represents a stored file part. |
| | | 49 | | /// </summary> |
| | | 50 | | public sealed record KrFilePart |
| | | 51 | | { |
| | | 52 | | /// <summary> |
| | | 53 | | /// Gets the field name associated with the file part. |
| | | 54 | | /// </summary> |
| | 1 | 55 | | public required string Name { get; init; } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Gets the original file name. |
| | | 59 | | /// </summary> |
| | 2 | 60 | | public required string OriginalFileName { get; init; } |
| | | 61 | | |
| | | 62 | | /// <summary> |
| | | 63 | | /// Gets the content type of the file. |
| | | 64 | | /// </summary> |
| | 1 | 65 | | public string ContentType { get; init; } = "application/octet-stream"; |
| | | 66 | | |
| | | 67 | | /// <summary> |
| | | 68 | | /// Gets the length of the stored file. |
| | | 69 | | /// </summary> |
| | 0 | 70 | | public long Length { get; init; } |
| | | 71 | | |
| | | 72 | | /// <summary> |
| | | 73 | | /// Gets the temporary storage path for the file. |
| | | 74 | | /// </summary> |
| | 1 | 75 | | public required string TempPath { get; init; } |
| | | 76 | | |
| | | 77 | | /// <summary> |
| | | 78 | | /// Gets the SHA-256 hash of the file if computed. |
| | | 79 | | /// </summary> |
| | 0 | 80 | | public string? Sha256 { get; init; } |
| | | 81 | | |
| | | 82 | | /// <summary> |
| | | 83 | | /// Gets the headers associated with the part. |
| | | 84 | | /// </summary> |
| | 1 | 85 | | public IReadOnlyDictionary<string, string[]> Headers { get; init; } = new ReadOnlyDictionary<string, string[]>(new D |
| | | 86 | | } |
| | | 87 | | |
| | | 88 | | /// <summary> |
| | | 89 | | /// Represents a stored raw part, preserving order in multipart/mixed payloads. |
| | | 90 | | /// </summary> |
| | | 91 | | public sealed record KrRawPart |
| | | 92 | | { |
| | | 93 | | /// <summary> |
| | | 94 | | /// Gets the optional part name. |
| | | 95 | | /// </summary> |
| | | 96 | | public string? Name { get; init; } |
| | | 97 | | |
| | | 98 | | /// <summary> |
| | | 99 | | /// Gets the content type of the part. |
| | | 100 | | /// </summary> |
| | | 101 | | public string ContentType { get; init; } = "application/octet-stream"; |
| | | 102 | | |
| | | 103 | | /// <summary> |
| | | 104 | | /// Gets the length of the stored part. |
| | | 105 | | /// </summary> |
| | | 106 | | public long Length { get; init; } |
| | | 107 | | |
| | | 108 | | /// <summary> |
| | | 109 | | /// Gets the temporary storage path for the part. |
| | | 110 | | /// </summary> |
| | | 111 | | public required string TempPath { get; init; } |
| | | 112 | | |
| | | 113 | | /// <summary> |
| | | 114 | | /// Gets the headers associated with the part. |
| | | 115 | | /// </summary> |
| | | 116 | | public IReadOnlyDictionary<string, string[]> Headers { get; init; } = new ReadOnlyDictionary<string, string[]>(new D |
| | | 117 | | |
| | | 118 | | /// <summary> |
| | | 119 | | /// Gets the nested multipart payload, if present. |
| | | 120 | | /// </summary> |
| | | 121 | | public IKrFormPayload? NestedPayload { get; init; } |
| | | 122 | | } |