Pprf.vala 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. public static int main(string[] args) {
  2. Ppub.CollectionServerRecord.resolve_records("libpeer.pcthingz.com");
  3. var creds = new Ppub.CollectionMemberCredentials.from_string("PYuKgL7SdQYc2Kf6UGG9pCE58m27qrYnCaM45cnxs64=:JbJ6OoNn2KcGX+Tk5C/hotGZCoHOkTNbadUrlk6aCRs=:tL+557eP7kE6ObAW0b5RjvYyU8Dl3oVTOvYA7LAwSdI9i4qAvtJ1BhzYp/pQYb2kITnybbuqticJozjlyfGzrg==:AJbFO6n/cOuD7kk+wu7DmQ58w6z0G3HsukVmIzxGaUM=");
  4. var collection_id = new Invercargill.BinaryData.from_base64("y8ibw54A93LDBKbgWm1EJ/WlbOkGX60DK+qp2lBHpjk=");
  5. var upload_file = File.new_for_path(args[1]);
  6. var file_size = upload_file.query_info("*", FileQueryInfoFlags.NONE).get_size();
  7. var client = new Pprf.HttpPprfClient("http://localhost:8080/test.php");
  8. var file_name = upload_file.get_basename();
  9. var collection = client.get_collection(collection_id);
  10. var member = Pprf.MemberIdentity.get_usable_identities(Invercargill.single(creds), collection).first_or_default();
  11. if(member == null) {
  12. print("No usable identity\n");
  13. return -2;
  14. }
  15. print(@"Acting as $(member.name)\n");
  16. print("Regisering name\n");
  17. var exists = false;
  18. try {
  19. client.register_name(collection_id, file_name, member);
  20. }
  21. catch(Pprf.Messages.PprfFailureError.NAME_EXISTS e) {
  22. print("Name already exists, will overwrite\n");
  23. exists = true;
  24. }
  25. print("Beginning upload\n");
  26. var file_stream = upload_file.read();
  27. var flags = exists ? Pprf.Messages.FinaliseUploadFlags.OVERWRITE_DESTINATION : 0;
  28. client.upload(collection_id, file_stream, file_size, file_name, exists, member, null, flags);
  29. print("Computing publication signature\n");
  30. var digest = Pprf.Util.file_checksum(upload_file);
  31. var publication = new Ppub.CollectionPublication(file_name, new DateTime.now_local(), member.name, creds, digest);
  32. print("Publishing publication\n");
  33. client.publish(collection_id, publication, member);
  34. print("Done\n");
  35. return 0;
  36. }