Compare commits

...

2 commits

Author SHA1 Message Date
uwaa
c38829a1b2 pleroma: add filename parameter 2025-01-14 11:58:51 +00:00
uwaa
616837db6d pleroma: merge react methods 2025-01-14 11:58:40 +00:00

View file

@ -358,7 +358,7 @@ public class Pleroma
/// <param name="mime">The MIME type of the file.</param> /// <param name="mime">The MIME type of the file.</param>
/// <param name="file">An array containing the file's contents.</param> /// <param name="file">An array containing the file's contents.</param>
/// <returns>A handle of the uploaded file, including its ID and URLs.</returns> /// <returns>A handle of the uploaded file, including its ID and URLs.</returns>
public Task<Attachment> Upload(CommonMIMEs mime, byte[] file) => Upload(CommonMIMEString(mime), file); public Task<Attachment> Upload(CommonMIMEs mime, byte[] file, string name = "file") => Upload(CommonMIMEString(mime), file, name);
/// <summary> /// <summary>
/// Uploads a file to the server. The resulting attachment can then be included in a status as an attachment. /// Uploads a file to the server. The resulting attachment can then be included in a status as an attachment.
@ -366,7 +366,7 @@ public class Pleroma
/// <param name="mime">The MIME type of the file.</param> /// <param name="mime">The MIME type of the file.</param>
/// <param name="file">An array containing the file's contents.</param> /// <param name="file">An array containing the file's contents.</param>
/// <returns>A handle of the uploaded file, including its ID and URLs.</returns> /// <returns>A handle of the uploaded file, including its ID and URLs.</returns>
public Task<Attachment> Upload(string mime, byte[] file) => Upload(mime, new ByteArrayContent(file)); public Task<Attachment> Upload(string mime, byte[] file, string name = "file") => Upload(mime, new ByteArrayContent(file), name);
/// <summary> /// <summary>
/// Uploads a file to the server. The resulting attachment can then be included in a status as an attachment. /// Uploads a file to the server. The resulting attachment can then be included in a status as an attachment.
@ -374,7 +374,7 @@ public class Pleroma
/// <param name="mime">The MIME type of the file.</param> /// <param name="mime">The MIME type of the file.</param>
/// <param name="stream">A stream of the file's contents.</param> /// <param name="stream">A stream of the file's contents.</param>
/// <returns>A handle of the uploaded file, including its ID and URLs.</returns> /// <returns>A handle of the uploaded file, including its ID and URLs.</returns>
public Task<Attachment> Upload(CommonMIMEs mime, Stream stream) => Upload(CommonMIMEString(mime), stream); public Task<Attachment> Upload(CommonMIMEs mime, Stream stream, string name = "file") => Upload(CommonMIMEString(mime), stream, name);
/// <summary> /// <summary>
/// Uploads a file to the server. The resulting attachment can then be included in a status as an attachment. /// Uploads a file to the server. The resulting attachment can then be included in a status as an attachment.
@ -382,9 +382,9 @@ public class Pleroma
/// <param name="mime">The MIME type of the file.</param> /// <param name="mime">The MIME type of the file.</param>
/// <param name="stream">A stream of the file's contents.</param> /// <param name="stream">A stream of the file's contents.</param>
/// <returns>A handle of the uploaded file, including its ID and URLs.</returns> /// <returns>A handle of the uploaded file, including its ID and URLs.</returns>
public Task<Attachment> Upload(string mime, Stream stream) => Upload(mime, new StreamContent(stream)); public Task<Attachment> Upload(string mime, Stream stream, string name = "file") => Upload(mime, new StreamContent(stream), name);
async Task<Attachment> Upload(string mime, HttpContent content) async Task<Attachment> Upload(string mime, HttpContent content, string name)
{ {
return (await Retry<Attachment>(() => return (await Retry<Attachment>(() =>
{ {
@ -392,7 +392,7 @@ public class Pleroma
content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{ {
Name = "\"file\"", Name = "\"file\"",
FileName = $"\"{Random.Shared.NextInt64()}\"", FileName = $"\"{name}\"",
}; };
MultipartFormDataContent form = [content]; MultipartFormDataContent form = [content];
@ -772,22 +772,12 @@ public class Pleroma
} }
/// <summary> /// <summary>
/// Adds a unicode reaction to a status. /// Adds a reaction to a status.
/// </summary> /// </summary>
/// <param name="status">The status to react to.</param> /// <param name="status">The status to react to.</param>
/// <param name="emoji">The unicode emoji.</param> /// <param name="emoji">The unicode emoji or custom emoji.</param>
/// <returns>The new state of the status, if it exists.</returns> /// <returns>The new state of the status, if it exists.</returns>
public Task<Status?> React(StatusID status, char emoji) => ReactInline(status, emoji.ToString()); public Task<Status?> React(StatusID status, string emoji)
/// <summary>
/// Adds a custom reaction to a status.
/// </summary>
/// <param name="status">The status to react to.</param>
/// <param name="emojiName">The custom emoji's name.</param>
/// <returns>The new state of the status, if it exists.</returns>
public Task<Status?> React(StatusID status, string emojiName) => ReactInline(status, $":{emojiName}:");
Task<Status?> ReactInline(StatusID status, string emoji)
{ {
return Retry<Status?>(() => new HttpRequestMessage(HttpMethod.Put, $"/api/v1/pleroma/statuses/{WebUtility.UrlEncode(status.ID)}/reactions/{WebUtility.UrlEncode(emoji)}")); return Retry<Status?>(() => new HttpRequestMessage(HttpMethod.Put, $"/api/v1/pleroma/statuses/{WebUtility.UrlEncode(status.ID)}/reactions/{WebUtility.UrlEncode(emoji)}"));
} }