Browse Source

use mounted file

neural-inex
Inex Code 5 months ago
parent
commit
4ffb74614e
  1. 14
      bin/server.dart

14
bin/server.dart

@ -50,11 +50,11 @@ Future<void> _importPosts(fileUri) async { @@ -50,11 +50,11 @@ Future<void> _importPosts(fileUri) async {
}
// Read posts.json and add posts to it
final postsJson = json.decode(await File('posts.json').readAsString());
final postsJson = json.decode(await File('/data/posts.json').readAsString());
postsJson.addAll(posts);
// Write posts.json
await File('posts.json').writeAsString(json.encode(postsJson));
await File('/data/posts.json').writeAsString(json.encode(postsJson));
// Delete file
await file.delete();
@ -70,11 +70,11 @@ Future<void> _importPosts(fileUri) async { @@ -70,11 +70,11 @@ Future<void> _importPosts(fileUri) async {
/// If an array is empty, do nothing.
/// Delete posted post from posts.json
Future<void> _postRandomPost() async {
if (!File('posts.json').existsSync()) {
if (!File('/data/posts.json').existsSync()) {
return;
}
final postsJson = json.decode(await File('posts.json').readAsString());
final postsJson = json.decode(await File('/data/posts.json').readAsString());
if (postsJson.isEmpty) {
return;
@ -82,7 +82,7 @@ Future<void> _postRandomPost() async { @@ -82,7 +82,7 @@ Future<void> _postRandomPost() async {
final post = postsJson.removeAt(Random().nextInt(postsJson.length));
await File('posts.json').writeAsString(json.encode(postsJson));
await File('/data/posts.json').writeAsString(json.encode(postsJson));
await _postOnMastodon(post);
@ -91,8 +91,8 @@ Future<void> _postRandomPost() async { @@ -91,8 +91,8 @@ Future<void> _postRandomPost() async {
void main(List<String> args) async {
// If posts.json does not exist, create it and write an empty array
if (!File('posts.json').existsSync()) {
await File('posts.json').writeAsString(json.encode([]));
if (!File('/data/posts.json').existsSync()) {
await File('/data/posts.json').writeAsString(json.encode([]));
}
// Import posts from files

Loading…
Cancel
Save