realtime_handler.dart 1016 B

123456789101112131415161718192021222324252627282930313233
  1. import 'package:jiffy/jiffy.dart';
  2. import 'package:shelf/shelf.dart';
  3. import 'package:supabase/supabase.dart';
  4. Future<Response> handleRealtime(Request request) async {
  5. // Check authorization
  6. final authHeader = request.headers['authorization'];
  7. if (authHeader == null || !authHeader.startsWith('Bearer ')) {
  8. return Response.forbidden('Authorization header missing or invalid');
  9. }
  10. final token = authHeader.substring(7); // Remove 'Bearer ' prefix
  11. // Initialize Supabase client with the bearer token
  12. final supabase = SupabaseClient(
  13. 'http://baas.fares.cyou:8000',
  14. token,
  15. );
  16. final channel = supabase.channel('csvhichstorage');
  17. final res = await channel.sendBroadcastMessage(
  18. event: "upload",
  19. payload: {
  20. "filename": "exportPGRGPN.zip",
  21. "updated_at": Jiffy.now().dateTime.toIso8601String(),
  22. },
  23. );
  24. print("res: $res");
  25. supabase.dispose();
  26. return Response.ok(
  27. '{"status": "success","res":$res}',
  28. headers: {'Content-Type': 'application/json'},
  29. );
  30. }