WIP add phone pointer import

This commit is contained in:
nolash 2021-04-08 09:54:39 +02:00
parent 81b71316ee
commit 3448e41d5b
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 28 additions and 3 deletions

View File

@ -18,7 +18,7 @@ class Phone extends Syncable implements Addressable {
}
public static async toKey(msisdn:number) {
return await toKey(msisdn.toString(), ':cic.msisdn');
return await toKey(msisdn.toString(), ':cic.phone');
}
public key(): string {

View File

@ -101,6 +101,7 @@ function importMeta(keystore) {
const file = files[i];
if (file.substr(-5) != '.json') {
console.debug('skipping file', file);
continue;
}
const filePath = path.join(workDir, file);
doOne(keystore, filePath);

View File

@ -85,7 +85,7 @@ random.seed()
def genPhoneIndex(phone):
h = hashlib.new('sha256')
h.update(phone.encode('utf-8'))
h.update(b'cic.phone')
h.update(b':cic.phone')
return h.digest().hex()

View File

@ -7,6 +7,7 @@ import argparse
import uuid
import datetime
import time
import phonenumbers
from glob import glob
# external imports
@ -67,6 +68,9 @@ os.makedirs(user_new_dir)
meta_dir = os.path.join(args.user_dir, 'meta')
os.makedirs(meta_dir)
phone_dir = os.path.join(args.user_dir, 'phone')
os.makedirs(os.path.join(phone_dir, 'meta'))
user_old_dir = os.path.join(args.user_dir, 'old')
os.stat(user_old_dir)
@ -166,10 +170,30 @@ if __name__ == '__main__':
f.write(json.dumps(o))
f.close()
meta_key = generate_metadata_pointer(bytes.fromhex(new_address_clean), 'cic.person')
meta_key = generate_metadata_pointer(bytes.fromhex(new_address_clean), ':cic.person')
meta_filepath = os.path.join(meta_dir, '{}.json'.format(new_address_clean.upper()))
os.symlink(os.path.realpath(filepath), meta_filepath)
phone_object = phonenumbers.parse(u.tel)
phone = phonenumbers.format_number(phone_object, phonenumbers.PhoneNumberFormat.E164)
meta_phone_key = generate_metadata_pointer(phone.encode('utf-8'), ':cic.phone')
meta_phone_filepath = os.path.join(phone_dir, 'meta', meta_phone_key)
filepath = os.path.join(
phone_dir,
'new',
meta_phone_key[:2].upper(),
meta_phone_key[2:4].upper(),
meta_phone_key.upper(),
)
os.makedirs(os.path.dirname(filepath), exist_ok=True)
f = open(filepath, 'w')
f.write(to_checksum_address(new_address_clean))
f.close()
os.symlink(os.path.realpath(filepath), meta_phone_filepath)
i += 1
sys.stdout.write('imported {} {}'.format(i, u).ljust(200) + "\r")