Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ private void UpdateSettingsView(object? instance)
GitHubGist => new GithubGistUploaderSettingsView() { DataContext = instance },
Hastebin => new HastebinUploaderSettingsView() { DataContext = instance },
OneTimeSecret => new OneTimeSecretUploadSettingsView() { DataContext = instance },
VoidedHostUploader => new ImageUploaders.VoidedHostUploaderSettingsView { DataContext = instance },
VoidedHostTextUploader => new ImageUploaders.VoidedHostUploaderSettingsView { DataContext = instance },
VoidedHostFileUploader => new ImageUploaders.VoidedHostUploaderSettingsView { DataContext = instance },
FTP or SFTP => new FTPSettingsView() { DataContext = instance },
// Add other mappings here:
// AmazonS3 => new S3SettingsView { DataContext = instance },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<UserControl
x:Class="SnapX.Avalonia.Views.Settings.Views.ImageUploaders.VoidedHostUploaderSettingsView"
xmlns="https://github.com/avaloniaui"
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<StackPanel Spacing="4">
<controls:SettingsExpander
Description="These settings apply to image, text, and file uploads via voided.host."
Header="Account"
IconSource="Contact"
IsExpanded="True">
<controls:SettingsExpanderItem Content="Don't have an account?">
<controls:SettingsExpanderItem.Footer>
<Button
Classes="accent"
Click="RegisterButton_OnClick"
Content="Create account"
x:Name="RegisterButton" />
</controls:SettingsExpanderItem.Footer>
</controls:SettingsExpanderItem>
<controls:SettingsExpanderItem Content="Upload as guest" Description="Use shared guest account instead of your personal key">
<controls:SettingsExpanderItem.Footer>
<CheckBox
x:Name="cbUseGuest" />
</controls:SettingsExpanderItem.Footer>
</controls:SettingsExpanderItem>
<controls:SettingsExpanderItem Content="Upload Key" x:Name="UploadKeyItem">
<controls:SettingsExpanderItem.Footer>
<TextBox
PasswordChar="*"
VerticalAlignment="Center"
Watermark="Paste your upload key here..."
Width="350"
x:Name="txtUploadKey" />
</controls:SettingsExpanderItem.Footer>
</controls:SettingsExpanderItem>
<controls:SettingsExpanderItem Content="Manage your upload keys on voided.host" x:Name="ManageKeysItem">
<controls:SettingsExpanderItem.Footer>
<Button
Click="ManageKeysButton_OnClick"
Content="Open key settings" />
</controls:SettingsExpanderItem.Footer>
</controls:SettingsExpanderItem>
</controls:SettingsExpander>
</StackPanel>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Avalonia.Controls;

Check warning on line 1 in SnapX.Avalonia/Views/Settings/Views/ImageUploaders/VoidedHostUploaderSettingsView.axaml.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

SnapX.Avalonia/Views/Settings/Views/ImageUploaders/VoidedHostUploaderSettingsView.axaml.cs#L1

Provide a 'CLSCompliant' attribute for assembly 'srcassembly.dll'.
using Avalonia.Interactivity;
using SnapX.Core.Upload.Img;
using SnapX.Core.Utils;

namespace SnapX.Avalonia.Views.Settings.Views.ImageUploaders;

public partial class VoidedHostUploaderSettingsView : UserControl

Check notice on line 8 in SnapX.Avalonia/Views/Settings/Views/ImageUploaders/VoidedHostUploaderSettingsView.axaml.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

SnapX.Avalonia/Views/Settings/Views/ImageUploaders/VoidedHostUploaderSettingsView.axaml.cs#L8

'partial' is gratuitous in this context.
{
public VoidedHostUploaderSettingsView()
{
InitializeComponent();
}

protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);

Check failure on line 17 in SnapX.Avalonia/Views/Settings/Views/ImageUploaders/VoidedHostUploaderSettingsView.axaml.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

SnapX.Avalonia/Views/Settings/Views/ImageUploaders/VoidedHostUploaderSettingsView.axaml.cs#L17

Potential null dereference detected.

if (DataContext is not (VoidedHostUploader or SnapX.Core.Upload.Text.VoidedHostTextUploader or SnapX.Core.Upload.File.VoidedHostFileUploader)) return;

Check notice on line 19 in SnapX.Avalonia/Views/Settings/Views/ImageUploaders/VoidedHostUploaderSettingsView.axaml.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

SnapX.Avalonia/Views/Settings/Views/ImageUploaders/VoidedHostUploaderSettingsView.axaml.cs#L19

Add curly braces around the nested statement(s) in this 'if' block.
var config = SnapX.Core.SnapXL.UploadersConfig;

bool guestKeyOk = VoidedHostUploader.IsGuestUploadKeyConfigured();
if (!guestKeyOk && config.VoidedHostUseGuest)
{
config.VoidedHostUseGuest = false;
}

cbUseGuest.IsChecked = guestKeyOk && config.VoidedHostUseGuest;
cbUseGuest.IsEnabled = guestKeyOk;
txtUploadKey.Text = config.VoidedHostUploadKey ?? "";

UpdateControlStates();

cbUseGuest.IsCheckedChanged += (_, _) =>
{
config.VoidedHostUseGuest = cbUseGuest.IsChecked == true;
UpdateControlStates();
};

txtUploadKey.TextChanged += (_, _) =>
{
config.VoidedHostUploadKey = txtUploadKey.Text ?? "";
};
}

private void UpdateControlStates()
{
bool guestKeyOk = VoidedHostUploader.IsGuestUploadKeyConfigured();
bool guest = guestKeyOk && cbUseGuest.IsChecked == true;

txtUploadKey.IsEnabled = !guest;
UploadKeyItem.IsEnabled = !guest;
ManageKeysItem.IsEnabled = !guest;
}

private void RegisterButton_OnClick(object? sender, RoutedEventArgs e)
{
URLHelpers.OpenURL(VoidedHostUploader.SnapXSetupRegisterUrl);
}

private void ManageKeysButton_OnClick(object? sender, RoutedEventArgs e)
{
URLHelpers.OpenURL(VoidedHostUploader.UploadKeySettingsUrl);
}
}
13 changes: 11 additions & 2 deletions SnapX.Avalonia/Views/Settings/Views/SettingsMainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,6 @@
<controls:NavigationViewItem Content="{Binding Source={x:Static upload:FileDestination.SharedFolder}, Converter={StaticResource EnumDescConverter}}" Tag="{x:Static upload:FileDestination.SharedFolder}" />
<controls:NavigationViewItem Content="{Binding Source={x:Static upload:FileDestination.Email}, Converter={StaticResource EnumDescConverter}}" Tag="{x:Static upload:FileDestination.Email}" />



</controls:NavigationViewItem.MenuItems>
</controls:NavigationViewItem>
<controls:NavigationViewItem Content="{Binding Source={x:Static upload:UploaderCategory.URLShorteners}, Converter={StaticResource EnumDescConverter}}" Tag="{x:Static upload:UploaderCategory.URLShorteners}">
Expand All @@ -374,6 +372,17 @@

</controls:NavigationViewItem.MenuItems>
</controls:NavigationViewItem>
<controls:NavigationViewItem Content="{Binding Source={x:Static upload:UploaderCategory.UniversalUploaders}, Converter={StaticResource EnumDescConverter}}" Tag="{x:Static upload:UploaderCategory.UniversalUploaders}">
<controls:NavigationViewItem.IconSource>
<fluent:FluentIconSource
Icon="Apps"
IconSize="Size24"
IconVariant="Regular" />
</controls:NavigationViewItem.IconSource>
<controls:NavigationViewItem.MenuItems>
<controls:NavigationViewItem Content="{Binding Source={x:Static upload:ImageDestination.VoidedHost}, Converter={StaticResource EnumDescConverter}}" Tag="{x:Static upload:ImageDestination.VoidedHost}" />
</controls:NavigationViewItem.MenuItems>
</controls:NavigationViewItem>
<controls:NavigationViewItem Content="Custom uploaders" Tag="CustomUploader">
<controls:NavigationViewItem.IconSource>
<fluent:FluentIconSource
Expand Down
6 changes: 6 additions & 0 deletions SnapX.Core/Upload/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public enum ImageDestination
Chevereto,
[Description("vgy.me")]
Vgyme,
[Description("voided.host")]
VoidedHost,
CustomImageUploader, // Localized
FileUploader // Localized
}
Expand All @@ -36,6 +38,8 @@ public enum TextDestination
Hastebin,
[Description("OneTimeSecret")]
OneTimeSecret,
[Description("voided.host")]
VoidedHost,
CustomTextUploader, // Localized
FileUploader // Localized
}
Expand Down Expand Up @@ -95,6 +99,8 @@ public enum FileDestination
YouTube,
[Description("Vault.ooo")]
Vault_ooo,
[Description("voided.host")]
VoidedHost,
SharedFolder, // Localized
Email, // Localized
CustomFileUploader // Localized
Expand Down
55 changes: 55 additions & 0 deletions SnapX.Core/Upload/File/VoidedHostFileUploader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

Check warning on line 1 in SnapX.Core/Upload/File/VoidedHostFileUploader.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

SnapX.Core/Upload/File/VoidedHostFileUploader.cs#L1

Provide a 'CLSCompliant' attribute for assembly 'srcassembly.dll'.
// SPDX-License-Identifier: GPL-3.0-or-later

Check notice on line 3 in SnapX.Core/Upload/File/VoidedHostFileUploader.cs

View check run for this annotation

codefactor.io / CodeFactor

SnapX.Core/Upload/File/VoidedHostFileUploader.cs#L3

Code should not contain multiple blank lines in a row. (SA1507)

using System.Diagnostics.CodeAnalysis;
using SnapX.Core.Upload.BaseServices;
using SnapX.Core.Upload.BaseUploaders;
using SnapX.Core.Upload.Img;
using SnapX.Core.Upload.Utils;

namespace SnapX.Core.Upload.File;

public class VoidedHostFileUploaderService : FileUploaderService
{
public override FileDestination EnumValue => FileDestination.VoidedHost;

public override bool CheckConfig(UploadersConfig config) => VoidedHostUploader.IsUploadConfigured(config);

Check failure on line 17 in SnapX.Core/Upload/File/VoidedHostFileUploader.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

SnapX.Core/Upload/File/VoidedHostFileUploader.cs#L17

Potential null dereference detected.

public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
{
bool useGuest = VoidedHostUploader.ShouldUseGuestMode(config);

Check failure on line 21 in SnapX.Core/Upload/File/VoidedHostFileUploader.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

SnapX.Core/Upload/File/VoidedHostFileUploader.cs#L21

Potential null dereference detected.
string key = VoidedHostUploader.GetEffectiveUploadKey(config);

Check failure on line 22 in SnapX.Core/Upload/File/VoidedHostFileUploader.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

SnapX.Core/Upload/File/VoidedHostFileUploader.cs#L22

Potential null dereference detected.

return new VoidedHostFileUploader(key, useGuest);
}
}

public sealed class VoidedHostFileUploader : FileUploader
{
private readonly VoidedHostMultipartUploader _multipart;

public VoidedHostFileUploader(string uploadKey, bool useGuestMode)
{
_multipart = new VoidedHostMultipartUploader(uploadKey, useGuestMode, VoidedHostUploader.FileUploadApiUrl);
_multipart.ProgressChanged += OnProgressChanged;
_multipart.EarlyURLCopyRequested += OnEarlyURLCopyRequested;
}

[RequiresDynamicCode("Uploader")]
[RequiresUnreferencedCode("Uploader")]
public override UploadResult Upload(Stream stream, string? fileName)
{
Errors.Errors.Clear();
_multipart.BufferSize = BufferSize;
UploadResult result = _multipart.Upload(stream, fileName);

Check failure on line 45 in SnapX.Core/Upload/File/VoidedHostFileUploader.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

SnapX.Core/Upload/File/VoidedHostFileUploader.cs#L45

Potential null dereference detected.
Errors.Add(_multipart.Errors);
return result;
}

public override void StopUpload()
{
_multipart.StopUpload();
base.StopUpload();
}
}
Loading