Skip to content

Commit

Permalink
opt.: bulk import servers (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit authored Aug 3, 2024
1 parent b8e5418 commit 610f46d
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 30 deletions.
22 changes: 22 additions & 0 deletions lib/data/model/server/server_private_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,28 @@ class ServerPrivateInfo {
String toString() {
return id;
}

static const example = ServerPrivateInfo(
name: 'name',
ip: 'ip',
port: 22,
user: 'root',
pwd: 'pwd',
keyId: 'private_key_id',
tags: ['tag1', 'tag2'],
alterUrl: 'user@ip:port',
autoConnect: true,
jumpId: 'jump_server_id',
custom: ServerCustom(
pveAddr: 'http://localhost:8006',
pveIgnoreCert: false,
cmds: {
'echo': 'echo hello',
},
preferTempDev: 'nvme-pci-0400',
logoUrl: 'https://example.com/logo.png',
),
);
}

class _IpPort {
Expand Down
1 change: 0 additions & 1 deletion lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bioAuth": "Biozertifizierung",
"browser": "Browser",
"bulkImportServers": "Server im Batch importieren",
"bulkImportServersTip": "Sie können das [Format]({url}) hier finden.",
"canPullRefresh": "Danach: herunterziehen zum Aktualisieren",
"cancel": "Abbrechen",
"choose": "Auswählen",
Expand Down
1 change: 0 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bioAuth": "Biometric auth",
"browser": "Browser",
"bulkImportServers": "Batch import servers",
"bulkImportServersTip": "You can find the [format]({url}) here.",
"canPullRefresh": "You can pull to refresh.",
"cancel": "Cancel",
"choose": "Choose",
Expand Down
1 change: 0 additions & 1 deletion lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bioAuth": "Autenticación biométrica",
"browser": "Navegador",
"bulkImportServers": "Importar servidores en masa",
"bulkImportServersTip": "Puede encontrar el [formato]]({url}) aquí.",
"canPullRefresh": "Se puede deslizar hacia abajo para refrescar",
"cancel": "Cancelar",
"choose": "Elegir",
Expand Down
1 change: 0 additions & 1 deletion lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bioAuth": "Authentification biométrique",
"browser": "Navigateur",
"bulkImportServers": "Importation groupée des serveurs",
"bulkImportServersTip": "Vous pouvez trouver le [format]({url}) ici.",
"canPullRefresh": "Vous pouvez tirer pour rafraîchir.",
"cancel": "Annuler",
"choose": "Choisir",
Expand Down
1 change: 0 additions & 1 deletion lib/l10n/app_id.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bioAuth": "Biosertifikasi",
"browser": "Peramban",
"bulkImportServers": "Impor server secara massal",
"bulkImportServersTip": "Anda dapat menemukan [format]({url}) di sini.",
"canPullRefresh": "Anda dapat menarik untuk menyegarkan.",
"cancel": "Membatalkan",
"choose": "Memilih",
Expand Down
1 change: 0 additions & 1 deletion lib/l10n/app_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bioAuth": "生体認証",
"browser": "ブラウザ",
"bulkImportServers": "サーバーを一括インポートする",
"bulkImportServersTip": "[こちら]({url})でフォーマットを見つけることができます",
"canPullRefresh": "引っ張って更新できます",
"cancel": "キャンセル",
"choose": "選択",
Expand Down
1 change: 0 additions & 1 deletion lib/l10n/app_nl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bioAuth": "Biometrische authenticatie",
"browser": "Browser",
"bulkImportServers": "Servers batchgewijs importeren",
"bulkImportServersTip": "U kunt het [formaat]({url}) hier vinden.",
"canPullRefresh": "Je kunt verversen door te slepen.",
"cancel": "Annuleren",
"choose": "Kiezen",
Expand Down
1 change: 0 additions & 1 deletion lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bioAuth": "Autenticação biométrica",
"browser": "Navegador",
"bulkImportServers": "Importar servidores em lote",
"bulkImportServersTip": "Você pode encontrar o [formato]({url}) aqui.",
"canPullRefresh": "Pode puxar para atualizar",
"cancel": "Cancelar",
"choose": "Escolher",
Expand Down
1 change: 0 additions & 1 deletion lib/l10n/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bioAuth": "биометрическая аутентификация",
"browser": "Браузер",
"bulkImportServers": "Пакетный импорт серверов",
"bulkImportServersTip": "[Формат]({url}) можно найти здесь.",
"canPullRefresh": "можно обновить, потянув вниз",
"cancel": "отмена",
"choose": "выбрать",
Expand Down
7 changes: 2 additions & 5 deletions lib/l10n/app_tr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bioAuth": "Biyometrik kimlik doğrulama",
"browser": "Tarayıcı",
"bulkImportServers": "Toplu sunucu içe aktarma",
"bulkImportServersTip": "[Formatı]({url}) burada bulabilirsiniz.",
"canPullRefresh": "Yenilemek için aşağı çekebilirsiniz.",
"cancel": "İptal",
"choose": "Seç",
Expand Down Expand Up @@ -75,7 +74,7 @@
"disk": "Disk",
"diskIgnorePath": "Disk için göz ardı edilen yol",
"displayCpuIndex": "CPU dizinini görüntüle",
"displayName": "Görünen ad",
"displayName": "Görünen ad",
"dl2Local": "{fileName} dosyasını yerel olarak indirmek istiyor musunuz?",
"doc": "Dokümantasyon",
"dockerEditHost": "DOCKER_HOST'u düzenle",
Expand Down Expand Up @@ -344,6 +343,4 @@
"write": "Yaz",
"writeScriptFailTip": "Komut dosyasına yazma başarısız oldu, muhtemelen izin eksikliğinden veya dizin mevcut olmadığından kaynaklanıyor olabilir.",
"writeScriptTip": "Sunucuya bağlandıktan sonra, sistem durumunu izlemek için ~/.config/server_box'a bir komut dosyası yazılacaktır. Komut dosyası içeriğini inceleyebilirsiniz."
}


}
1 change: 0 additions & 1 deletion lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bioAuth": "生物认证",
"browser": "浏览器",
"bulkImportServers": "批量导入服务器",
"bulkImportServersTip": "可以在这里找到[格式]({url})",
"canPullRefresh": "可以下拉刷新",
"cancel": "取消",
"choose": "选择",
Expand Down
1 change: 0 additions & 1 deletion lib/l10n/app_zh_tw.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bioAuth": "生物認證",
"browser": "瀏覽器",
"bulkImportServers": "批量導入伺服器",
"bulkImportServersTip": "您可以在此處找到[格式]({url})",
"canPullRefresh": "可以下拉更新",
"cancel": "取消",
"choose": "選擇",
Expand Down
16 changes: 6 additions & 10 deletions lib/view/page/backup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import 'dart:io';
import 'package:computer/computer.dart';
import 'package:fl_lib/fl_lib.dart';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:server_box/core/extension/context/locale.dart';
import 'package:server_box/core/utils/sync/icloud.dart';
import 'package:server_box/core/utils/sync/webdav.dart';
import 'package:server_box/data/model/app/backup.dart';
import 'package:server_box/data/model/server/server_private_info.dart';
import 'package:server_box/data/res/misc.dart';
import 'package:server_box/data/res/store.dart';
import 'package:server_box/data/res/url.dart';

class BackupPage extends StatelessWidget {
BackupPage({super.key});
Expand Down Expand Up @@ -204,12 +202,6 @@ class BackupPage extends StatelessWidget {
return CardX(
child: ListTile(
title: Text(l10n.bulkImportServers),
subtitle: SimpleMarkdown(
data: l10n.bulkImportServersTip(Urls.appWiki),
styleSheet: MarkdownStyleSheet(
p: UIs.textGrey,
),
),
leading: const Icon(Icons.import_export),
onTap: () => _onBulkImportServers(context),
trailing: const Icon(Icons.keyboard_arrow_right),
Expand Down Expand Up @@ -400,8 +392,12 @@ class BackupPage extends StatelessWidget {
}

void _onBulkImportServers(BuildContext context) async {
final text = await Pfs.pickFileString();
if (text == null) return;
final data = await context.showImportDialog(
title: l10n.server,
modelDef: ServerPrivateInfo.example.toJson(),
);
if (data == null) return;
final text = String.fromCharCodes(data);

try {
final (spis, err) = await context.showLoadingDialog(
Expand Down
11 changes: 8 additions & 3 deletions lib/view/page/snippet/edit.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';

import 'package:computer/computer.dart';
import 'package:fl_lib/fl_lib.dart';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
Expand Down Expand Up @@ -105,7 +106,7 @@ class _SnippetEditPageState extends State<SnippetEditPage>

Widget _buildBody() {
return ListView(
padding: const EdgeInsets.symmetric(horizontal:13),
padding: const EdgeInsets.symmetric(horizontal: 13),
children: [
_buildImport(),
Input(
Expand Down Expand Up @@ -198,8 +199,12 @@ class _SnippetEditPageState extends State<SnippetEditPage>
);
if (data == null) return;
final str = String.fromCharCodes(data);
final list = json.decode(str) as List;
if (list.isEmpty) return;
final (list, _) = await context.showLoadingDialog(
fn: () => Computer.shared.start((s) {
return json.decode(s) as List;
}, str),
);
if (list == null || list.isEmpty) return;
final snippets = <Snippet>[];
final errs = <String>[];
for (final item in list) {
Expand Down
2 changes: 1 addition & 1 deletion lib/view/page/snippet/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class _SnippetListPageState extends State<SnippetListPage> {
.toList();

return ReorderableListView.builder(
padding: const EdgeInsets.symmetric(horizontal: 13),
padding: const EdgeInsets.symmetric(horizontal: 11),
itemCount: filtered.length,
onReorder: (oldIdx, newIdx) => setState(() {
provider.snippets.moveByItem(
Expand Down

0 comments on commit 610f46d

Please sign in to comment.