|
|
@@ -0,0 +1,38 @@
|
|
|
+import 'package:jiffy/jiffy.dart';
|
|
|
+import 'package:shelf/shelf.dart';
|
|
|
+import 'package:supabase/supabase.dart';
|
|
|
+
|
|
|
+Future<Response> handleRealtime(Request request) async {
|
|
|
+ // Check authorization
|
|
|
+ final authHeader = request.headers['authorization'];
|
|
|
+ if (authHeader == null || !authHeader.startsWith('Bearer ')) {
|
|
|
+ return Response.forbidden('Authorization header missing or invalid');
|
|
|
+ }
|
|
|
+ final token = authHeader.substring(7); // Remove 'Bearer ' prefix
|
|
|
+
|
|
|
+ final contentType = request.headers['content-type'];
|
|
|
+ if (contentType == null || !contentType.contains('multipart/form-data')) {
|
|
|
+ return Response(400, body: 'Unsupported content-type');
|
|
|
+ }
|
|
|
+
|
|
|
+ // Initialize Supabase client with the bearer token
|
|
|
+ final supabase = SupabaseClient(
|
|
|
+ 'http://baas.fares.cyou:8000',
|
|
|
+ token,
|
|
|
+ );
|
|
|
+
|
|
|
+ final channel = supabase.channel('csvhichstorage');
|
|
|
+ final res = await channel.sendBroadcastMessage(
|
|
|
+ event: "upload",
|
|
|
+ payload: {
|
|
|
+ "filename": "exportPGRGPN.zip",
|
|
|
+ "updated_at": Jiffy.now().dateTime.toIso8601String(),
|
|
|
+ },
|
|
|
+ );
|
|
|
+ print("res: $res");
|
|
|
+ supabase.dispose();
|
|
|
+ return Response.ok(
|
|
|
+ '{"status": "success","res":$res}',
|
|
|
+ headers: {'Content-Type': 'application/json'},
|
|
|
+ );
|
|
|
+}
|