v0.1
This commit is contained in:
parent
8d99b55818
commit
7e37546ae9
108 changed files with 6063 additions and 1450 deletions
|
@ -24,46 +24,86 @@ function requestList(login,database,rootwindow,callback) {
|
|||
function dataRequest(login,photoID,database,rootwindow) {
|
||||
// check if image exist and call download function
|
||||
Helperjs.friendicaRequest(login,"/api/friendica/photo?photo_id="+photoID, rootwindow, function (image){
|
||||
try{ if(image==""){currentimageno=currentimageno+1}else{
|
||||
var obj = JSON.parse(image);
|
||||
var helpfilename=obj.filename.substring(0,obj.filename.lastIndexOf("."));
|
||||
var filesuffix="";
|
||||
if (obj.type=="image/jpeg"){filesuffix=".jpg"}
|
||||
else if (obj.type=="image/png"){filesuffix=".png"}
|
||||
else {filesuffix=""}
|
||||
|
||||
if (helpfilename==""){// check if file has any filename
|
||||
obj.filename=obj["id"]+filesuffix;
|
||||
}
|
||||
else{obj.filename=helpfilename+filesuffix}
|
||||
|
||||
var link="";
|
||||
if(obj["link"][0]){link=obj["link"][0]} else{link=obj["link"]["4"]}
|
||||
xhr.setUrl(Qt.resolvedUrl(link));
|
||||
xhr.setFilename(login.imagestore+'albums/'+obj.album+"/"+obj["filename"]);
|
||||
xhr.setDownloadtype("picture");
|
||||
xhr.download();
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
db.transaction( function(tx) {
|
||||
var result = tx.executeSql('SELECT * from imageData where id = "'+obj["id"]+'"');
|
||||
if(result.rows.length === 1) {// use update
|
||||
result = tx.executeSql('UPDATE imageData SET username ="' +login.username+ '",id="'+obj.id+'", created="'+obj.created+'", edited="'+obj.edited+'", profile="'+obj.profile+'", link="'+obj["link"]["4"]+'", filename="'+obj.filename+'",title="'+obj.title+'", desc="'+obj.desc+'", type="'+obj.type+'", width="'+obj.width+'", height="'+obj.height+'", album="'+obj.album+'", location="file://'+login.imagestore+'albums/'+obj.album+'/" where id="'+obj["id"]+'"');
|
||||
} else {// use insert print('... does not exists, create it')
|
||||
result = tx.executeSql('INSERT INTO imageData VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [login.username,obj.id,obj.created,obj.edited, obj.title, obj.desc, obj.album, obj.filename, obj.type, obj.height, obj.width,obj. profile,obj["link"]["4"],'file://'+login.imagestore+'albums/'+obj.album+"/"]);
|
||||
}
|
||||
})}}
|
||||
try{ if(image==""){currentimageno=currentimageno+1}else{
|
||||
var obj = JSON.parse(image);
|
||||
var helpfilename=obj.filename.substring(0,obj.filename.lastIndexOf("."));
|
||||
var filesuffix="";
|
||||
if (obj.type=="image/jpeg"){filesuffix=".jpg"}
|
||||
else if (obj.type=="image/png"){filesuffix=".png"}
|
||||
else {filesuffix=""}
|
||||
if (helpfilename==""){// check if file has any filename
|
||||
obj.filename=obj["id"]+filesuffix;
|
||||
}
|
||||
else{obj.filename=helpfilename+filesuffix}
|
||||
var link="";
|
||||
if(obj["link"][0]){link=obj["link"][0]} else{link=obj["link"]["4"]}
|
||||
xhr.setUrl(Qt.resolvedUrl(link));
|
||||
xhr.setFilename(login.imagestore+'albums/'+obj.album+"/"+obj["filename"]);
|
||||
xhr.setDownloadtype("picture");
|
||||
xhr.download();
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
db.transaction( function(tx) {
|
||||
var result = tx.executeSql('SELECT * from imageData where id = "'+obj["id"]+'"');
|
||||
if(result.rows.length === 1) {// use update
|
||||
result = tx.executeSql('UPDATE imageData SET username ="' +login.username+ '",id="'+obj.id+'", created="'+obj.created+'", edited="'+obj.edited+'", profile="'+obj.profile+'", link="'+obj["link"]["4"]+'", filename="'+obj.filename+'",title="'+obj.title+'", desc="'+obj.desc+'", type="'+obj.type+'", width="'+obj.width+'", height="'+obj.height+'", album="'+obj.album+'", location="file://'+login.imagestore+'albums/'+obj.album+'/" where id="'+obj["id"]+'"');
|
||||
} else {// use insert print('... does not exists, create it')
|
||||
result = tx.executeSql('INSERT INTO imageData VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [login.username,obj.id,obj.created,obj.edited, obj.title, obj.desc, obj.album, obj.filename, obj.type, obj.height, obj.width,obj. profile,obj["link"]["4"],'file://'+login.imagestore+'albums/'+obj.album+"/"]);
|
||||
}
|
||||
})}}
|
||||
catch (e){print("Data retrieval failure! "+ e+obj);}
|
||||
})}
|
||||
|
||||
|
||||
function deleteImageData(database,user,field,selection,callback) { // does nothing useful at the moment
|
||||
function deleteImage(database,login,type,location,rootwindow,callback) { // delete image locally and on server
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
//print(' delete Image Data() for ' + location)
|
||||
var rsfilename=location.substring(location.lastIndexOf("/")+1,location.length);
|
||||
var rslocation=location.substring(0,location.lastIndexOf("/")+1);
|
||||
print(type+" Name "+ rsfilename+" Location: "+rslocation)
|
||||
db.transaction( function(tx) {
|
||||
if (type=='image'){
|
||||
var rs= tx.executeSql('SELECT * FROM imageData WHERE filename="'+rsfilename+'" AND location="'+rslocation+'"')
|
||||
print(rs.rows.item(0).id) //);
|
||||
var imageId=rs.rows.item(0).id;
|
||||
Helperjs.friendicaPostRequest(login,"/api/friendica/photo/delete?photo_id="+imageId,"","DELETE",rootwindow, function (obj){
|
||||
var deletereturn = JSON.parse(obj); print(obj);
|
||||
if (deletereturn.result=="deleted"){
|
||||
db.transaction( function(tx) {
|
||||
var deleters=tx.executeSql('DELETE FROM imageData WHERE location="'+rslocation+'" AND filename="'+rsfilename+'"'); });
|
||||
filesystem.Directory=rslocation.substring(7,rslocation.length-1);
|
||||
filesystem.rmFile(rsfilename)
|
||||
}})
|
||||
}
|
||||
else{
|
||||
Helperjs.friendicaPostRequest(login,"/api/friendica/photoalbum/delete?album="+rsfilename,"","DELETE",rootwindow, function (obj){
|
||||
print(" Return "+ obj);
|
||||
var deletereturn = JSON.parse(obj);
|
||||
if (deletereturn.result=="deleted"){
|
||||
db.transaction( function(tx) {
|
||||
var rs= tx.executeSql('SELECT DISTINCT location FROM imageData WHERE album="'+rsfilename+'" AND username="'+login.username+'"');
|
||||
var locationstring=rs.rows.item(0).location;
|
||||
filesystem.Directory=locationstring.substring(7,locationstring.length-1);
|
||||
filesystem.rmDir();
|
||||
var deleters=tx.executeSql('DELETE FROM imageData WHERE album="'+location+'"');
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
callback(location)
|
||||
})
|
||||
}
|
||||
|
||||
function deleteContacts(database,user,callback) { // does nothing useful at the moment
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
//print(' delete Image Data() for ' + field +"="+selection)
|
||||
db.transaction( function(tx) {
|
||||
result = tx.executeSql('UPDATE imageData SET data="" where '+ field +'="'+selection+'"');
|
||||
result1= tx.executeSql('SELECT * FROM contacts a LEFT OUTER JOIN news b ON a.url==b.uid');
|
||||
result2= tx.executeSql('SELECT * FROM contacts a LEFT OUTER JOIN news b ON a.url==b.uid');
|
||||
|
||||
|
||||
|
||||
callback(result)})
|
||||
}
|
||||
|
||||
function requestFriendsAlbumPictures(login,friend,rootwindow,callback){
|
||||
// screenscraping of albums page of contact without user and password
|
||||
Helperjs.friendicaWebRequest(friend.url.replace("profile","photos"),rootwindow,function(photohtml){
|
||||
|
@ -98,7 +138,6 @@ function requestFriendsPictures(link,rootwindow,callback){
|
|||
for (var i=0;i<arr.length-1;i++){
|
||||
var photoname=arr[i].substring(arr[i].lastIndexOf('alt')+5,arr[i].lastIndexOf('title')-2);
|
||||
var thumblink=arr[i].substring(arr[i].lastIndexOf('<img')+10,arr[i].lastIndexOf('alt')-2);
|
||||
|
||||
var imagetype=thumblink.substring(thumblink.lastIndexOf("."));
|
||||
var photolink=thumblink.substring(0,thumblink.length-imagetype.length-2)+"-0"+imagetype
|
||||
if(thumblink.substring(0,4)!=="http"){thumblink=basehtml+thumblink}
|
||||
|
@ -106,8 +145,8 @@ function requestFriendsPictures(link,rootwindow,callback){
|
|||
var photo={'link':photolink,'name':photoname,'thumb':thumblink}
|
||||
photoarray.push(photo);
|
||||
}
|
||||
callback(photoarray)
|
||||
})
|
||||
callback(photoarray)
|
||||
})
|
||||
}
|
||||
|
||||
// CONFIG FUNCTIONS
|
||||
|
@ -119,7 +158,7 @@ function initDatabase(database) { // initialize the database object
|
|||
tx.executeSql('CREATE TABLE IF NOT EXISTS imageData(username TEXT,id INT, created TEXT,edited TEXT, title TEXT, desc TEXT, album TEXT,filename TEXT, type TEXT, height INT, width INT, profile INT, link TEXT,location TEXT)');
|
||||
tx.executeSql('CREATE TABLE IF NOT EXISTS config(server TEXT, username TEXT, password TEXT, imagestore TEXT, maxnews INT, timerInterval INT, newsViewType TEXT,isActive INT, permissions TEXT,maxContactAge INT,APIVersion TEXT,layout TEXT, addons TEXT)');
|
||||
tx.executeSql('CREATE TABLE IF NOT EXISTS news(username TEXT, messagetype INT, text TEXT, created_at INT, in_reply_to_status_id INT, source TEXT, status_id INT, in_reply_to_user_id INT, geo TEXT,favorited TEXT, uid INT, statusnet_html TEXT, statusnet_conversation_id TEXT,friendica_activities TEXT, friendica_activities_self TEXT, attachments TEXT, friendica_owner INT)');
|
||||
tx.executeSql('CREATE TABLE IF NOT EXISTS contacts(username TEXT, id INT, name TEXT, screen_name TEXT, location TEXT,imageAge INT, profile_image_url TEXT, description TEXT, profile_image BLOB, url TEXT, protected TEXT, followers_count INT, friends_count INT, created_at INT, favourites_count TEXT, utc_offset TEXT, time_zone TEXT, statuses_count INT, following TEXT, verified TEXT, statusnet_blocking TEXT, notifications TEXT, statusnet_profile_url TEXT, cid INT, network TEXT, isFriend INT)');
|
||||
tx.executeSql('CREATE TABLE IF NOT EXISTS contacts(username TEXT, id INT, name TEXT, screen_name TEXT, location TEXT,imageAge INT, profile_image_url TEXT, description TEXT, profile_image BLOB, url TEXT, protected TEXT, followers_count INT, friends_count INT, created_at INT, favourites_count TEXT, utc_offset TEXT, time_zone TEXT, statuses_count INT, following TEXT, verified TEXT, statusnet_blocking TEXT, notifications TEXT, statusnet_profile_url TEXT, cid INT, network TEXT, isFriend INT, timestamp INT)');
|
||||
tx.executeSql('CREATE TABLE IF NOT EXISTS groups(username TEXT, groupname TEXT, gid INT, members TEXT)');
|
||||
tx.executeSql('CREATE TABLE IF NOT EXISTS events(username TEXT, id INT, start INT, end INT, allday INT, title TEXT, j INT, d TEXT, isFirst INT, uid INT, cid INT, uri TEXT, created INT, edited INT, desc TEXT, location TEXT, type TEXT, nofinish TEXT, adjust INT, ignore INT, permissions TEXT, guid INT, itemid INT, plink TEXT, authorName TEXT, authorAvatar TEXT, authorLink TEXT, html TEXT)');
|
||||
})}
|
||||
|
@ -208,6 +247,7 @@ function requestFriendsEvents(login,friend,rootwindow,callback){
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
function savePermissions(database,obj) { // stores config to DB
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
var permissions=JSON.stringify(obj)
|
||||
|
@ -240,7 +280,7 @@ Helperjs.friendicaWebRequest(url+"/api/statusnet/config",rootwindow, function (o
|
|||
"\nText limit: "+serverconfig.site.textlimit+"\nShort Url length: "+serverconfig.site.shorturllength+
|
||||
"\nFriendica version: "+serverconfig.site.friendica.FRIENDICA_VERSION+"\nDFRN version: "+serverconfig.site.friendica.DFRN_PROTOCOL_VERSION +
|
||||
"\nDB Update version: "+serverconfig.site.friendica.DB_UPDATE_VERSION+"'}";
|
||||
callback(serverConfigString)
|
||||
callback(serverConfigString)
|
||||
})}
|
||||
|
||||
|
||||
|
@ -317,6 +357,21 @@ function cleanNews(database,callback){
|
|||
})
|
||||
}
|
||||
|
||||
function cleanContacts(login,database,callback){
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
db.transaction( function(tx) {
|
||||
var oldestnewsrs= tx.executeSql('SELECT created_at FROM news WHERE username="'+login.username+'" AND messagetype=0 ORDER BY created_at ASC LIMIT 1');
|
||||
var oldestnewsTime=oldestnewsrs.rows.item(0).created_at- 604800000; //contacts can be 7 days old
|
||||
print(login.username+" älteste news: "+ oldestnewsTime);
|
||||
var result = tx.executeSql('SELECT * from contacts WHERE username="'+login.username+'" AND isFriend=0 AND imageAge<'+oldestnewsTime); // check for friends
|
||||
for (var i=0;i<result.rows.length;i++){
|
||||
filesystem.rmFile(result.rows.item(i).profile_image);
|
||||
var deleters = tx.executeSql('DELETE from contacts WHERE username="'+login.username+'" AND url="'+result.rows.item(i).url+'"');
|
||||
}
|
||||
callback()
|
||||
})
|
||||
}
|
||||
|
||||
function processNews(callback){
|
||||
// Newsjs.getCurrentContacts(login,db,function(contacts){
|
||||
// contactlist=contacts});
|
||||
|
@ -359,23 +414,34 @@ function updateContactInDB(login,database,isFriend,contact){// for newstab and f
|
|||
// var suffix=contact.profile_image_url.substring(contact.profile_image_url.lastIndexOf("."), contact.profile_image_url.length);
|
||||
// var imagename=login.imagestore+"contacts/"+contact.screen_name.trim()+suffix;
|
||||
|
||||
var imagename="";
|
||||
contacttimer.restart();
|
||||
var imagename="";
|
||||
contacttimer.restart();
|
||||
var currentTime=Date.now();
|
||||
if(contact.profile_image_url==""){root.currentContact=root.currentContact+1 } else{//print(JSON.stringify(contact))
|
||||
imagename=login.imagestore+"contacts/"+contact.screen_name+"-"+contact.profile_image_url.substring(contact.profile_image_url.lastIndexOf("/")+1, contact.profile_image_url.length);
|
||||
|
||||
xhr.setUrl(Qt.resolvedUrl(contact.profile_image_url));
|
||||
xhr.setFilename(imagename);
|
||||
xhr.setDownloadtype("contact");
|
||||
xhr.download();}
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
var result;
|
||||
db.transaction( function(tx) {
|
||||
var image_timestamp=0;
|
||||
if(contact.profile_image_url==""){root.currentContact=root.currentContact+1 }
|
||||
else{//print(JSON.stringify(contact))
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
db.transaction( function(tx) {
|
||||
var currentts=0;
|
||||
var currenttsrs= tx.executeSql('SELECT timestamp FROM contacts WHERE username="'+login.username+'" AND url="'+contact.url+'"');
|
||||
try{currentts=currenttsrs.rows.item(0).timestamp}catch(e){}
|
||||
|
||||
var imagename_helper=[];
|
||||
imagename_helper=contact.profile_image_url.split('?');//print("substring: "+JSON.stringify(imagename_helper)+imagename_helper[0].substring(imagename_helper[0].lastIndexOf("/")+1, imagename_helper[0].length))
|
||||
imagename=login.imagestore+"contacts/"+contact.screen_name+"-"+imagename_helper[0].substring(imagename_helper[0].lastIndexOf("/")+1, imagename_helper[0].length);
|
||||
try {parseInt(image_timestamp=imagename_helper[1].substring(imagename_helper[1].indexOf("ts=")+3,imagename_helper[1].length))} catch(e){};
|
||||
print(contact.screen_name+" Timestamp"+image_timestamp+" "+ new Date(parseInt(image_timestamp)*1000));
|
||||
if ((image_timestamp>currentts) || (image_timestamp==0)){
|
||||
xhr.setUrl(Qt.resolvedUrl(contact.profile_image_url));
|
||||
xhr.setFilename(imagename);
|
||||
xhr.setDownloadtype("contact");
|
||||
xhr.download();
|
||||
}
|
||||
var result;
|
||||
result = tx.executeSql('SELECT * from contacts where username="'+login.username+'" AND url = "'+contact.url+'"'); // check for news url
|
||||
if(result.rows.length === 1) {// use update
|
||||
result = tx.executeSql('UPDATE contacts SET id='+contact.id+', name="'+Qt.btoa(contact.name)+'", screen_name="'+contact.screen_name+'", location="'+contact.location+'",imageAge='+currentTime+', profile_image_url="'+contact.profile_image_url+'", description="'+Qt.btoa(contact.description)+'", profile_image="'+imagename+'", protected="'+contact.protected+'", followers_count='+contact.followers_count+', friends_count='+contact.friends_count+', created_at="'+ Date.parse(Newsjs.cleanDate(contact.created_at))+'", favourites_count="'+contact.favorites_count+'", utc_offset="'+contact.utc_offset+'", time_zone="'+contact.time_zone+'", statuses_count='+contact.statuses_count+', following="'+contact.following+'", verified ="'+contact.verified+'", statusnet_blocking="'+contact.statusnet_blocking+'", notifications="'+contact.notifictions+'", statusnet_profile_url="'+contact.statusnet_profile_url+'", cid='+contact.cid+', network="'+contact.network+'", isFriend='+isFriend+' where username="'+login.username+'" AND url="'+contact.url+'"');
|
||||
result = tx.executeSql('UPDATE contacts SET id='+contact.id+', name="'+Qt.btoa(contact.name)+'", screen_name="'+contact.screen_name+'", location="'+contact.location+'",imageAge='+currentTime+', profile_image_url="'+contact.profile_image_url+'", description="'+Qt.btoa(contact.description)+'", profile_image="'+imagename+'", protected="'+contact.protected+'", followers_count='+contact.followers_count+', friends_count='+contact.friends_count+', created_at="'+ Date.parse(Newsjs.cleanDate(contact.created_at))+'", favourites_count="'+contact.favorites_count+'", utc_offset="'+contact.utc_offset+'", time_zone="'+contact.time_zone+'", statuses_count='+contact.statuses_count+', following="'+contact.following+'", verified ="'+contact.verified+'", statusnet_blocking="'+contact.statusnet_blocking+'", notifications="'+contact.notifictions+'", statusnet_profile_url="'+contact.statusnet_profile_url+'", cid='+contact.cid+', network="'+contact.network+'", isFriend='+isFriend+', timestamp='+ image_timestamp+' where username="'+login.username+'" AND url="'+contact.url+'"');
|
||||
} else {// use insert
|
||||
result = tx.executeSql('INSERT INTO contacts VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [login.username,contact.id,Qt.btoa(contact.name),contact.screen_name,contact.location,currentTime,contact.profile_image_url, Qt.btoa(contact.description),imagename,contact.url,contact.protected,contact.followers_count, contact.friends_count,Date.parse(Newsjs.cleanDate(contact.created_at)),contact.favorites_count,contact.utc_offset,contact.time_zone,contact.statuses_count,contact.following,contact.verfied,contact.statusnet_blocking,contact.notifications,contact.statusnet_profile_url,contact.cid,contact.network,isFriend]);}
|
||||
result = tx.executeSql('INSERT INTO contacts VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [login.username,contact.id,Qt.btoa(contact.name),contact.screen_name,contact.location,currentTime,contact.profile_image_url, Qt.btoa(contact.description),imagename,contact.url,contact.protected,contact.followers_count, contact.friends_count,Date.parse(Newsjs.cleanDate(contact.created_at)),contact.favorites_count,contact.utc_offset,contact.time_zone,contact.statuses_count,contact.following,contact.verfied,contact.statusnet_blocking,contact.notifications,contact.statusnet_profile_url,contact.cid,contact.network,isFriend,image_timestamp]);}
|
||||
});
|
||||
}
|
||||
}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue