-
Notifications
You must be signed in to change notification settings - Fork 3
/
Settings.pm
59 lines (43 loc) · 1.64 KB
/
Settings.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package Plugins::1001Albums::Settings;
use strict;
use base qw(Slim::Web::Settings);
use JSON::XS::VersionOneAndTwo;
use Slim::Utils::Prefs;
my $prefs = preferences('plugin.1001albums');
my $log = Slim::Utils::Log::logger('plugin.1001albums');
sub name { Slim::Web::HTTP::CSRF->protectName('PLUGIN_1001_ALBUMS_SHORT') }
sub page { 'plugins/1001Albums/settings.html' }
sub prefs {
return ($prefs, qw(username));
}
sub handler {
my ($class, $client, $params, $callback, @args) = @_;
if ($params->{saveSettings} && $params->{pref_username} ne $prefs->get('username')) {
my $cb = sub {
my ($response, $error) = @_;
my $profile = eval { from_json($response->content) } unless $error;
if ($error || $@ || !$profile) {
delete $params->{saveSettings};
$error ||= $@ || 'profile not found';
$log->error("Failed profile validation: $error");
$params->{validation_error} = Slim::Utils::Strings::string('PLUGIN_1001_ALBUMS_FAILED_VALIDATION', $error);
}
elsif (main::DEBUGLOG && $log->is_debug) {
$log->debug(Data::Dump::dump($profile));
}
elsif (main::INFOLOG && $log->is_info) {
my $limitedProfile = Storable::dclone($profile);
$limitedProfile->{history} = ['...'];
$log->info(Data::Dump::dump($limitedProfile));
}
return $callback->( $client, $params, $class->SUPER::handler($client, $params), @args );
};
Slim::Networking::SimpleAsyncHTTP->new($cb, $cb, {
cache => 0,
})->get(Plugins::1001Albums::Plugin::ALBUM_URL . URI::Escape::uri_escape_utf8($params->{pref_username}));
return;
}
$params->{infolink} = Plugins::1001Albums::Plugin::BASE_URL;
return $class->SUPER::handler($client, $params);
}
1;