chiark / gitweb /
Use DOMParser instead of JQuery.
authorMarnanel Thurman <marnanel@thurman.org.uk>
Sun, 12 Dec 2021 06:23:15 +0000 (06:23 +0000)
committerMarnanel Thurman <marnanel@thurman.org.uk>
Sun, 12 Dec 2021 06:23:53 +0000 (06:23 +0000)
Some further fixes to make use of Promises correctly.

grok.js
package.json

diff --git a/grok.js b/grok.js
index 96ac3c77c3cc127fe717647de4b8c7c548d9737e..89d949d6c2930d425dbba8d459f84ca500bab143 100644 (file)
--- a/grok.js
+++ b/grok.js
@@ -10,11 +10,12 @@ import {
 
 import * as SecureStore from 'expo-secure-store';
 import tough from 'tough-cookie';
+import DOMParser from 'react-native-html-parser';
 
 ///////////////////////////////////////
 
 //var DREAMWIDTH_URL = 'https://dreamwidth.org';
-var DREAMWIDTH_URL = 'http://aspidistra:6887'; // FIXME temporary
+var DREAMWIDTH_URL = 'https://marnanel.org'; // FIXME temporary
 
 export var grok_url = DREAMWIDTH_URL;
 
@@ -62,32 +63,17 @@ export function grok_set_url(url) {
 
 export async function grok_login1() {
 
-    var cookieString = await SecureStore.getItemAsync('cookies');
-
     return new Promise((resolve, reject) => {
 
         var result = {};
 
-        console.log("Sending cookies: "+cookieString);
-
         fetch(grok_url, {
-            method: 'POST',
-            body: make_post_body(
-                {
-                    'lj_form_auth': auth,
-                    'user': username,
-                    'password': password,
-                    'remember_me': 1,
-                    'login': 'Log+in',
-                }),
-            headers: {
-                'Cookie': cookieString,
-            },
+            method: 'GET',
         }).then((response) => {
 
-            var parser = new DOMParser();
+            var parser = new DOMParser.DOMParser();
             var doc = parser.parseFromString(
-                response.data, 'text/html');
+                response.text(), 'text/html');
 
             result['auth'] = doc.querySelectorAll(
                 'name="lj_form_auth"]')[0].
@@ -160,13 +146,10 @@ export async function grok_login2(auth, username, password) {
                 console.log(blockquote);
             }
 
-            callback(result);
+            resolve(result);
 
         }).catch((error) => {
-            result['success'] = false;
-            result['message'] = error;
-
-            callback(result);
+            reject(error);
         });
     });
 }
index 4796471251bcdb38484b3b748e00a129e76a7894..806944a6417baf7181497b64ae22f53406efbe2f 100644 (file)
@@ -37,6 +37,7 @@
     "react": "17.0.1",
     "react-dom": "17.0.1",
     "react-native": "0.64.3",
+    "react-native-html-parser": "^0.1.0",
     "react-native-safe-area-context": "3.3.2",
     "react-native-screens": "~3.8.0",
     "react-native-web": "0.17.1",