Created
January 8, 2023 13:24
-
-
Save Zfinix/1747160a45893a1fab077fcd5e17ee66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'package:dart_frog/dart_frog.dart'; | |
import 'package:tweety/request_handler.dart'; | |
import 'package:tweety/tweety_core.dart'; | |
Future<Response> onRequest(RequestContext context) async { | |
return requestHandler( | |
() async { | |
final param = context.request.uri.queryParameters.entries.first; | |
final core = context.read<TweetyCore>(); | |
await core.initialize(); | |
await core.goto(param.value); | |
if (param.key == 'text') { | |
final text = await core.getTweetText<dynamic>(); | |
return Response.json(body: {'data': text}); | |
} | |
if (param.key == 'screenshot') { | |
final screenshot = await core.screenshotTweet(); | |
return Response.bytes( | |
body: screenshot, | |
headers: { | |
HttpHeaders.contentTypeHeader: 'image/png', | |
HttpHeaders.accessControlAllowOriginHeader: '*', | |
}, | |
); | |
} | |
await core.closeBrowser(); | |
return null; | |
}, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment