Skip to content

Commit 21f40e4

Browse files
committed
clean(code): refractor and clean up code
1 parent 5ce4780 commit 21f40e4

File tree

6 files changed

+61
-25
lines changed

6 files changed

+61
-25
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Music Sharity - Share music across all platforms
3+
* Copyright (C) 2026 Sikelio (Byte Roast)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
class RateLimitException implements Exception {
19+
final String message;
20+
final Duration waitTime;
21+
22+
RateLimitException(this.message, this.waitTime);
23+
24+
@override
25+
String toString() => message;
26+
}

lib/models/odesli_result.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Music Sharity - Share music across all platforms
3+
* Copyright (C) 2026 Sikelio (Byte Roast)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
import 'track_metadata.dart';
19+
20+
class OdesliResult {
21+
final Map<String, String> platformLinks;
22+
final TrackMetadata? metadata;
23+
24+
OdesliResult({required this.platformLinks, this.metadata});
25+
}

lib/pages/conversion_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import 'package:flutter/material.dart';
2121
import 'package:flutter/services.dart';
2222
import 'package:music_sharity/services/conversion_history_service.dart';
2323
import 'package:share_plus/share_plus.dart';
24+
import '../exceptions/rate_limit_exception.dart';
2425
import '../models/music_link.dart';
2526
import '../models/music_platform.dart';
27+
import '../models/odesli_result.dart';
2628
import '../pages/home_page.dart';
2729
import '../services/music_converter_service.dart';
28-
import '../services/odesli_service.dart';
29-
import '../services/rate_limiter_service.dart';
3030
import '../utils/ui_helpers.dart';
3131
import '../widgets/platform_card.dart';
3232
import '../widgets/rate_limit_indicator.dart';

lib/services/music_converter_service.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
import 'odesli_service.dart';
1919
import '../models/music_link.dart';
20+
import '../models/odesli_result.dart';
2021

2122
class MusicConverterService {
2223
final OdesliService _odesliService = OdesliService();

lib/services/odesli_service.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@ import 'dart:convert';
1919
import 'package:flutter/foundation.dart' show kIsWeb;
2020
import 'package:http/http.dart' as http;
2121
import 'rate_limiter_service.dart';
22+
import '../exceptions/rate_limit_exception.dart';
23+
import '../models/odesli_result.dart';
2224
import '../models/track_metadata.dart';
2325

24-
class OdesliResult {
25-
final Map<String, String> platformLinks;
26-
final TrackMetadata? metadata;
27-
28-
OdesliResult({required this.platformLinks, this.metadata});
29-
}
30-
3126
class OdesliService {
3227
static const String _baseUrl = 'https://api.song.link/v1-alpha.1/links';
3328
static const String _cloudflareWorkerUrl =

lib/services/rate_limiter_service.dart

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
*/
1818
import 'dart:async';
1919
import 'package:shared_preferences/shared_preferences.dart';
20+
import '../exceptions/rate_limit_exception.dart';
2021

2122
class RateLimiterService {
23+
static final RateLimiterService _instance = RateLimiterService._internal();
24+
factory RateLimiterService() => _instance;
25+
RateLimiterService._internal();
26+
2227
static const int maxRequests = 10;
2328
static const Duration windowDuration = Duration(minutes: 1);
2429
static const String _storageKey = 'rate_limiter_timestamps';
@@ -30,12 +35,6 @@ class RateLimiterService {
3035
bool _isInitialized = false;
3136
Completer<void>? _initializationCompleter;
3237

33-
static final RateLimiterService _instance = RateLimiterService._internal();
34-
35-
factory RateLimiterService() => _instance;
36-
37-
RateLimiterService._internal();
38-
3938
Future<void> _loadTimestamps() async {
4039
if (_isInitialized) return;
4140

@@ -156,13 +155,3 @@ class RateLimiterService {
156155
_quotaController.close();
157156
}
158157
}
159-
160-
class RateLimitException implements Exception {
161-
final String message;
162-
final Duration waitTime;
163-
164-
RateLimitException(this.message, this.waitTime);
165-
166-
@override
167-
String toString() => message;
168-
}

0 commit comments

Comments
 (0)