Fixed CORS
This commit is contained in:
@@ -16,7 +16,7 @@ const Center noMenuWidget = Center(
|
|||||||
style: TextStyle(fontSize: 20, fontStyle: FontStyle.italic)));
|
style: TextStyle(fontSize: 20, fontStyle: FontStyle.italic)));
|
||||||
|
|
||||||
const String hashLink =
|
const String hashLink =
|
||||||
"http://github.com/kphanipavan/IIITB_Menu/releases/download/latest/out.txt";
|
"https://raw.githubusercontent.com/kphanipavan/IIITB_Menu/menu_scraper/out.txt";
|
||||||
|
|
||||||
const String dataLink =
|
const String dataLink =
|
||||||
"http://github.com/kphanipavan/IIITB_Menu/releases/download/latest/out.json";
|
"https://raw.githubusercontent.com/kphanipavan/IIITB_Menu/menu_scraper/out.json";
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
// ignore_for_file: unnecessary_this, file_names
|
// ignore_for_file: unnecessary_this, file_names, library_prefixes
|
||||||
|
|
||||||
import "dart:convert";
|
import "dart:convert";
|
||||||
// import "dart:io";
|
|
||||||
import "package:iiitb_menu/constants.dart";
|
import "package:iiitb_menu/constants.dart";
|
||||||
// import "package:path_provider/path_provider.dart";
|
// import "package:path_provider/path_provider.dart";
|
||||||
// import 'dart:io';
|
import 'dart:io';
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
// import "package:crypto/crypto.dart";
|
import "package:crypto/crypto.dart";
|
||||||
// import "package:http/http.dart";
|
import "package:http/http.dart";
|
||||||
import "package:intl/intl.dart";
|
import "package:intl/intl.dart";
|
||||||
// import "package:shared_preferences/shared_preferences.dart";
|
import "package:shared_preferences/shared_preferences.dart";
|
||||||
// import "package:dio/dio.dart";
|
// import "package:dio/dio.dart";
|
||||||
import "package:iiitb_menu/data.dart" as menuData;
|
import "package:iiitb_menu/data.dart" as menuData;
|
||||||
|
|
||||||
@@ -31,87 +30,89 @@ class GlobalModel extends ChangeNotifier {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// static Future<String> getLatestHash() async {
|
static Future<String> getLatestHash() async {
|
||||||
// try {
|
try {
|
||||||
// // Request hashRequest = Request("get", Uri.parse(hashLink));
|
Response hashRequest = await get(Uri.parse(hashLink));
|
||||||
// Response ret = await Dio().request(hashLink,
|
// Response ret = await Dio().request(hashLink,
|
||||||
// options: Options(method: 'GET', headers: {
|
// options: Options(method: 'GET', headers: {
|
||||||
// HttpHeaders.acceptHeader: "text/plain",
|
// HttpHeaders.acceptHeader: "text/plain",
|
||||||
// "Access-Control-Allow-Origin": "*",
|
// "Access-Control-Allow-Origin": "*",
|
||||||
// "Access-Control-Allow-Methods": "GET",
|
// "Access-Control-Allow-Methods": "GET",
|
||||||
// "Access-Control-Allow-Headers": "*",
|
// "Access-Control-Allow-Headers": "*",
|
||||||
// "Access-Control-Max-Age": "1000"
|
// "Access-Control-Max-Age": "1000"
|
||||||
// }));
|
// }));
|
||||||
// if (ret.statusCode == 200) {
|
if (hashRequest.statusCode == 200) {
|
||||||
// return ret.data.replaceAll("\n", "");
|
return hashRequest.body.replaceAll("\n", "");
|
||||||
// } else {
|
} else {
|
||||||
// return "";
|
return "";
|
||||||
// }
|
}
|
||||||
// } on SocketException catch (exce) {
|
} on SocketException catch (exce) {
|
||||||
// print("Unable to download hash");
|
print("Unable to download hash");
|
||||||
// print(exce);
|
print(exce);
|
||||||
// return "";
|
return "";
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// static Future<String> getLatestData() async {
|
static Future<String> getLatestData() async {
|
||||||
// try {
|
try {
|
||||||
// Response ret = await Dio().request(dataLink,
|
// Response ret = await Dio().request(dataLink,
|
||||||
// options: Options(method: "GET", headers: {
|
// options: Options(method: "GET", headers: {
|
||||||
// HttpHeaders.acceptHeader: "text/plain",
|
// HttpHeaders.acceptHeader: "text/plain",
|
||||||
// "Access-Control-Allow-Origin": "*"
|
// "Access-Control-Allow-Origin": "*"
|
||||||
// }));
|
// }));
|
||||||
// return ret.data;
|
Response dataRequest = await get(Uri.parse(dataLink));
|
||||||
// } on SocketException catch (exce) {
|
return dataRequest.body;
|
||||||
// print("Unable to download any data");
|
} on SocketException catch (exce) {
|
||||||
// print(exce);
|
print("Unable to download any data");
|
||||||
// return "";
|
print(exce);
|
||||||
// }
|
return "";
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static Future<Map> loadData() async {
|
static Future<Map> loadData() async {
|
||||||
late Map returnData;
|
late Map returnData;
|
||||||
// Directory appDir = await getApplicationDocumentsDirectory();
|
// Directory appDir = await getApplicationDocumentsDirectory();
|
||||||
// final SharedPreferences prefs = await SharedPreferences.getInstance();
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
// String? rawData;
|
String? rawData;
|
||||||
// String rawHash;
|
String rawHash;
|
||||||
// String fileName = "${appDir.path}/menu.json";
|
// String fileName = "${appDir.path}/menu.json";
|
||||||
// print(fileName);
|
// print(fileName);
|
||||||
// File fileLink = File(fileName);
|
// File fileLink = File(fileName);
|
||||||
// rawData = prefs.getString("asdasdasd");
|
rawData = prefs.getString(storageKey);
|
||||||
|
print(rawData);
|
||||||
|
if (rawData != null) {
|
||||||
|
print("data found");
|
||||||
|
// rawData = localStor.getItem("fullMenu");
|
||||||
|
rawHash = md5.convert(utf8.encode(rawData)).toString();
|
||||||
|
print("Hash of Raw Data:");
|
||||||
|
print(rawHash);
|
||||||
|
// print("RawData: ");
|
||||||
// print(rawData);
|
// print(rawData);
|
||||||
// if (rawData != null) {
|
returnData = jsonDecode(rawData);
|
||||||
// print("data found");
|
// menuAvailable = true;
|
||||||
// // rawData = localStor.getItem("fullMenu");
|
} else {
|
||||||
// rawHash = md5.convert(utf8.encode(rawData)).toString();
|
print("Data Not Found");
|
||||||
// print("Hash of Raw Data:");
|
returnData = {};
|
||||||
// print(rawHash);
|
rawHash = "";
|
||||||
// // print("RawData: ");
|
}
|
||||||
// // print(rawData);
|
String remoteHash = await GlobalModel.getLatestHash();
|
||||||
// returnData = jsonDecode(rawData);
|
|
||||||
// // menuAvailable = true;
|
|
||||||
// } else {
|
|
||||||
// print("Data Not Found");
|
|
||||||
// returnData = {};
|
|
||||||
// rawHash = "";
|
|
||||||
// }
|
|
||||||
// // String remoteHash = await GlobalModel.getLatestHash();
|
|
||||||
// String remoteHash = "asd";
|
// String remoteHash = "asd";
|
||||||
// print("Remote Hash: $remoteHash");
|
print("Remote Hash: $remoteHash");
|
||||||
// if (remoteHash == "") {
|
if (remoteHash == "") {
|
||||||
// } else if (remoteHash == rawHash) {
|
} else if (remoteHash == rawHash) {
|
||||||
// print("Remote hash $remoteHash is same as local hash $rawHash");
|
print("Remote hash $remoteHash is same as local hash $rawHash");
|
||||||
// } else {
|
} else {
|
||||||
// print("Remote hash $remoteHash is NOT the same as local hash $rawHash");
|
print("Remote hash $remoteHash is NOT the same as local hash $rawHash");
|
||||||
// print("Getting data from remote");
|
print("Getting data from remote");
|
||||||
// rawData = await getLatestData();
|
rawData = await getLatestData();
|
||||||
// if (rawData == "") {
|
if (rawData == "") {
|
||||||
// return {};
|
return {};
|
||||||
// }
|
}
|
||||||
// returnData = jsonDecode(rawData);
|
// print(rawData);
|
||||||
// // fileLink.writeAsStringSync(rawData, mode: FileMode.write);
|
returnData = jsonDecode(rawData);
|
||||||
// prefs.setString(storageKey, rawData);
|
// fileLink.writeAsStringSync(rawData, mode: FileMode.write);
|
||||||
// }
|
prefs.setString(storageKey, rawData);
|
||||||
|
}
|
||||||
returnData = jsonDecode(menuData.data);
|
returnData = jsonDecode(menuData.data);
|
||||||
return returnData;
|
return returnData;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import FlutterMacOS
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
import path_provider_foundation
|
import path_provider_foundation
|
||||||
|
import shared_preferences_foundation
|
||||||
|
|
||||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||||
|
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ dependencies:
|
|||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
provider: ^6.0.5
|
provider: ^6.0.5
|
||||||
# crypto: ^3.0.3
|
crypto: ^3.0.3
|
||||||
intl: ^0.18.1
|
intl: ^0.18.1
|
||||||
# http: ^1.1.0
|
http: ^1.1.0
|
||||||
# dio: ^5.3.2
|
# dio: ^5.3.2
|
||||||
path_provider:
|
path_provider:
|
||||||
# localstorage: ^4.0.1+4
|
# localstorage: ^4.0.1+4
|
||||||
# shared_preferences: ^2.2.0
|
shared_preferences: ^2.2.0
|
||||||
# sembast:
|
# sembast:
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
|||||||
Reference in New Issue
Block a user