Skip to content

Commit

Permalink
lints
Browse files Browse the repository at this point in the history
  • Loading branch information
mootw committed Sep 6, 2023
1 parent f3bf71c commit b3852cb
Show file tree
Hide file tree
Showing 23 changed files with 394 additions and 568 deletions.
6 changes: 3 additions & 3 deletions app/lib/screens/view_team_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ class _TeamViewPageState extends State<TeamViewPage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [

Flexible(
const Flexible(
child: Padding(
padding: const EdgeInsets.all(16),
padding: EdgeInsets.all(16),
child: Column(
children: [
const Text(
Text(
"TODO put some important fields here, maybe a specific notes box for important stuff: things that we need to check up on, things that are broken, if they need help and with what"),
],
)),
Expand Down
5 changes: 0 additions & 5 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ dev_dependencies:

flutter_launcher_icons: ^0.11.0

# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^2.0.0

# For information on the generic Dart part of this file, see the
Expand Down
5 changes: 5 additions & 0 deletions server/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include: package:lint/strict.yaml

analyzer:
errors:
todo: info
4 changes: 2 additions & 2 deletions server/lib/edit_lock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EditLock {
print(locks);
final value = locks[key];
if(value != null) {
if(value.add(Duration(minutes: 15)).isAfter(DateTime.now())) {
if(value.add(const Duration(minutes: 15)).isAfter(DateTime.now())) {
return true;
}
}
Expand All @@ -27,4 +27,4 @@ class EditLock {
locks.remove(key);
print(locks);
}
}
}
99 changes: 59 additions & 40 deletions server/lib/server.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:dotenv/dotenv.dart';
import 'package:rfc_6901/rfc_6901.dart';
import 'package:server/edit_lock.dart';
import 'package:shelf_gzip/shelf_gzip.dart';
import 'package:shelf_router/shelf_router.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:shelf_gzip/shelf_gzip.dart';
import 'package:shelf_router/shelf_router.dart';
import 'package:shelf_web_socket/shelf_web_socket.dart';
import 'dart:io';

import 'package:snout_db/patch.dart';
import 'package:snout_db/snout_db.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
Expand All @@ -23,7 +22,7 @@ Map<String, EventData> loadedEvents = {};
//To keep things simple we will just have 1 edit lock for all loaded events.
EditLock editLock = EditLock();

var app = Router();
final app = Router();

//Stuff that should be done for each event that is loaded.
class EventData {
Expand All @@ -49,15 +48,18 @@ void main(List<String> args) async {
await loadEvents();

app.get("/listen/<event>", (Request request, String event) {
var handler = webSocketHandler((WebSocketChannel webSocket) {
print('new listener for $event');
webSocket.sink.done
.then((value) => loadedEvents[event]?.listeners.remove(webSocket));
loadedEvents[event]?.listeners.add(webSocket);
// webSocket.stream.listen((message) {
// webSocket.sink.add("echo $message");
// });
}, pingInterval: Duration(hours: 8));
final handler = webSocketHandler(
(WebSocketChannel webSocket) {
print('new listener for $event');
webSocket.sink.done
.then((value) => loadedEvents[event]?.listeners.remove(webSocket));
loadedEvents[event]?.listeners.add(webSocket);
// webSocket.stream.listen((message) {
// webSocket.sink.add("echo $message");
// });
},
pingInterval: const Duration(hours: 8),
);

return handler(request);
});
Expand Down Expand Up @@ -94,76 +96,93 @@ void main(List<String> args) async {
});

app.get("/events/<eventID>", (Request request, String eventID) async {
File? f = loadedEvents[eventID]?.file;
final File? f = loadedEvents[eventID]?.file;
if (f == null || await f.exists() == false) {
return Response.notFound("Event not found");
}
final event = SnoutDB.fromJson(json.decode(await f.readAsString()));
final event = SnoutDB.fromJson(
json.decode(await f.readAsString()) as Map<String, dynamic>,
);

return Response.ok(json.encode(event), headers: {
'Content-Type':
ContentType('application', 'json', charset: 'utf-8').toString(),
});
return Response.ok(
json.encode(event),
headers: {
'Content-Type':
ContentType('application', 'json', charset: 'utf-8').toString(),
},
);
});

app.get("/events/<eventID>/patchDiff",
(Request request, String eventID) async {
File? f = loadedEvents[eventID]?.file;
final File? f = loadedEvents[eventID]?.file;
if (f == null || await f.exists() == false) {
return Response.notFound("Event not found");
}
final event = SnoutDB.fromJson(json.decode(await f.readAsString()));
final event = SnoutDB.fromJson(
json.decode(await f.readAsString()) as Map<String, dynamic>,
);

final clientHead = request.headers["head"];
if (clientHead == null) {
return Response(406, body: "send head");
}
int clientHeadInt = int.parse(clientHead);
final int clientHeadInt = int.parse(clientHead);

if (clientHeadInt < 1) {
return Response(406, body: 'head cannot be less than 1');
}

final range = event.patches.getRange(clientHeadInt, event.patches.length);

return Response.ok(json.encode(range.toList()), headers: {
'Content-Type':
ContentType('application', 'json', charset: 'utf-8').toString(),
});
return Response.ok(
json.encode(range.toList()),
headers: {
'Content-Type':
ContentType('application', 'json', charset: 'utf-8').toString(),
},
);
});

app.get("/events/<eventID>/<subPath|.*>",
(Request request, String eventID, String subPath) async {
File? f = loadedEvents[eventID]?.file;
final File? f = loadedEvents[eventID]?.file;
if (f == null || await f.exists() == false) {
return Response.notFound("Event not found");
}
final event = SnoutDB.fromJson(json.decode(await f.readAsString()));
final event = SnoutDB.fromJson(
json.decode(await f.readAsString()) as Map<String, dynamic>,
);

try {
var dbJson = json.decode(json.encode(event));
final pointer = JsonPointer('/$subPath');
dbJson = pointer.read(dbJson);
return Response.ok(json.encode(dbJson), headers: {
'Content-Type':
ContentType('application', 'json', charset: 'utf-8').toString(),
});
return Response.ok(
json.encode(dbJson),
headers: {
'Content-Type':
ContentType('application', 'json', charset: 'utf-8').toString(),
},
);
} catch (e) {
print(e);
return Response.internalServerError(body: e);
}
});

app.put("/events/<eventID>", (Request request, String eventID) async {
File? f = loadedEvents[eventID]?.file;
final File? f = loadedEvents[eventID]?.file;
if (f == null || await f.exists() == false) {
return Response.notFound("Event not found");
}
final event = SnoutDB.fromJson(json.decode(await f.readAsString()));
final event = SnoutDB.fromJson(
json.decode(await f.readAsString()) as Map<String, dynamic>,
);
try {
//Uses UTF-8 by default
String content = await request.readAsString();
Patch patch = Patch.fromJson(json.decode(content));
final String content = await request.readAsString();
final Patch patch = Patch.fromJson(json.decode(content) as Map);

event.addPatch(patch);

Expand All @@ -185,13 +204,13 @@ void main(List<String> args) async {
}
});

var handler = const Pipeline()
final handler = const Pipeline()
.addMiddleware(logRequests())
.addMiddleware(handleCORS())
.addMiddleware(gzipMiddleware)
.addHandler(app);
.addHandler(app.call);

HttpServer server =
final HttpServer server =
await shelf_io.serve(handler, InternetAddress.anyIPv4, serverPort);
//Enable GZIP compression since every byte counts and the performance hit is
//negligable for the 30%+ compression depending on how much of the data is image
Expand Down
8 changes: 8 additions & 0 deletions server/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.8.1"
lint:
dependency: "direct dev"
description:
name: lint
sha256: f4bd4dbaa39f4ae8836f2d1275f2f32bc68b3a8cce0a0735dd1f7a601f06682a
url: "https://pub.dev"
source: hosted
version: "2.1.2"
meta:
dependency: transitive
description:
Expand Down
15 changes: 8 additions & 7 deletions server/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ environment:
sdk: '>=3.0.0 <4.0.0'

dependencies:
snout_db:
path: ../snout_db

rfc_6901: ^0.1.1
dotenv: ^4.1.0
http: ^1.1.0

eval_ex: ^1.1.8
http: ^1.1.0
rfc_6901: ^0.1.1

shelf: ^1.4.1
shelf_gzip: ^4.0.1
shelf_router: ^1.1.4
shelf_web_socket: ^1.0.4

snout_db:
path: ../snout_db

web_socket_channel: ^2.4.0
shelf_gzip: ^4.0.1

dev_dependencies:
lint: 2.1.2
Loading

0 comments on commit b3852cb

Please sign in to comment.