Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
intranet-rest-fs-openacs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
project-open
intranet-rest-fs-openacs
Commits
bef79b00
Commit
bef79b00
authored
Jan 21, 2019
by
Frank Bergmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Last - more or less - working version before
starting to work with versions
parent
6d0e0dc7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
118 additions
and
50 deletions
+118
-50
Connection.js
posync/controller/Connection.js
+115
-46
File.js
posync/model/File.js
+0
-1
Operation.js
posync/model/Operation.js
+3
-3
No files found.
posync/controller/Connection.js
View file @
bef79b00
...
...
@@ -4,6 +4,7 @@
*
************************************************************/
Ext
.
define
(
'POSync.controller.Connection'
,
{
extend
:
'Ext.app.Controller'
,
id
:
'Connection'
,
...
...
@@ -45,6 +46,14 @@ Ext.define('POSync.controller.Connection', {
});
},
/**
* Convert a time to a PostgreSQL ISO date string
*/
timeToIso
:
function
(
time
)
{
var
date
=
new
Date
(
time
);
return
date
.
toISOString
().
replace
(
"T"
,
" "
).
replace
(
"Z"
,
""
);
},
/* FIXME: no easy way to know if login is successful */
login
:
function
(
request_options
)
{
var
me
=
this
;
...
...
@@ -177,14 +186,22 @@ Ext.define('POSync.controller.Connection', {
// Get the contents
var
dirTree
=
require
(
'directory-tree'
);
var
tree
=
dirTree
(
path
,{
attributes
:[
'mode'
,
'mtime'
,
'mtimeMs'
]});
this
.
fixLocalTree
(
tree
);
this
.
fixLocalTree
(
tree
,
projectId
);
this
.
localDirStore
.
loadTree
(
tree
);
this
.
localDirStore
.
isLoaded
=
projectId
;
},
/* Fix a tree before loading it */
fixLocalTree
:
function
(
tree
)
{
/**
* Fix a tree before loading it
*/
fixLocalTree
:
function
(
tree
,
projectId
)
{
var
me
=
this
;
// Get the project path
var
fs
=
require
(
'fs'
);
var
sha1File
=
require
(
'sha1-file'
);
if
(
tree
)
{
if
(
tree
.
type
==
'directory'
)
{
tree
.
type
=
'folder'
;
...
...
@@ -194,14 +211,11 @@ Ext.define('POSync.controller.Connection', {
tree
.
leaf
=
false
;
tree
.
mime_type
=
''
;
}
else
{
// const cp = require('child_process');
// tree.type = cp.execFileSync('/usr/bin/file', ['--brief', '--mime-type', tree.path]).toString();
// tree.sha1 = cp.execFileSync('/usr/bin/sha1sum', [tree.path]).toString().substr(0,40);
// tree.date = cp.execFileSync('/usr/bin/stat', ['-c', '%y', tree.path]).toString();
tree
.
sha1
=
'<sha1>'
;
tree
.
date
=
'<date>'
;
var
stats
=
fs
.
statSync
(
tree
.
path
);
tree
.
sha1
=
sha1File
(
tree
.
path
);
tree
.
modification_date
=
me
.
timeToIso
(
stats
.
mtimeMs
);
tree
.
creation_date
=
me
.
timeToIso
(
stats
.
birthtimeMs
);
tree
.
size
=
stats
.
size
;
tree
.
expandable
=
false
;
tree
.
expanded
=
false
;
tree
.
leaf
=
true
;
...
...
@@ -247,39 +261,42 @@ Ext.define('POSync.controller.Connection', {
// ********************************************************************
// Go through the list of remote files and check that a local file exists.
var
root
=
me
.
filesStore
.
getRootNode
();
root
.
cascadeBy
(
function
(
f
ile
)
{
if
(
"root"
==
f
ile
.
get
(
'id'
))
return
;
// Exclude folders and the root
root
.
cascadeBy
(
function
(
remoteF
ile
)
{
if
(
"root"
==
remoteF
ile
.
get
(
'id'
))
return
;
// Exclude folders and the root
var
pathArray
=
f
ile
.
getPathArray
();
var
pathArray
=
remoteF
ile
.
getPathArray
();
var
purePathArray
=
pathArray
.
slice
(
0
);
var
fileName
=
f
ile
.
get
(
'name'
);
var
fileName
=
remoteF
ile
.
get
(
'name'
);
pathArray
.
push
(
fileName
);
console
.
log
(
'Connection.sync remote: path='
+
pathArray
);
var
type
=
f
ile
.
get
(
'type'
);
var
type
=
remoteF
ile
.
get
(
'type'
);
switch
(
type
)
{
case
'file'
:
var
localFile
Found
=
me
.
localDirStore
.
searchUsingPathArray
(
pathArray
);
if
(
!
localFile
Found
)
{
var
localFile
=
me
.
localDirStore
.
searchUsingPathArray
(
pathArray
);
if
(
!
localFile
)
{
var
operation
=
Ext
.
create
(
'POSync.model.Operation'
,
{
id
:
'
op_'
+
file
.
get
(
'id
'
),
file_id
:
f
ile
.
get
(
'id'
),
id
:
'
download_'
+
pathArray
.
join
(
'_
'
),
file_id
:
remoteF
ile
.
get
(
'id'
),
file_path
:
purePathArray
.
join
(
'/'
),
file_name
:
f
ile
.
get
(
'name'
),
mime_type
:
f
ile
.
get
(
'mime_type'
),
file_name
:
remoteF
ile
.
get
(
'name'
),
mime_type
:
remoteF
ile
.
get
(
'mime_type'
),
file_sha1
:
null
,
local_file
:
localFile
,
remote_file
:
remoteFile
,
op
:
'download'
});
me
.
operationsStore
.
add
(
operation
);
}
else
{
// Compare local with remote file based on meta information
me
.
syncFileLocalRemote
(
projectId
,
localFile
,
remoteFile
);
}
break
;
case
'folder'
:
var
localFile
Found
=
me
.
localDirStore
.
searchUsingPathArray
(
purePathArray
);
if
(
!
localFile
Found
)
{
var
localFile
=
me
.
localDirStore
.
searchUsingPathArray
(
purePathArray
);
if
(
!
localFile
)
{
// Create a new local folder
var
fs
=
require
(
'fs'
);
// Get the project path
var
project
=
me
.
projectsStore
.
getById
(
''
+
projectId
);
var
projectPath
=
configData
.
topdir
+
'/'
+
project
.
get
(
'project_path'
);
var
path
=
projectPath
+
'/'
+
purePathArray
.
join
(
'/'
);
...
...
@@ -293,43 +310,52 @@ Ext.define('POSync.controller.Connection', {
// ********************************************************************
// Go through the list of local files and check that a remote file exists
var
root
=
me
.
localDirStore
.
getRootNode
();
root
.
cascadeBy
(
function
(
f
ile
)
{
if
(
"root"
==
f
ile
.
get
(
'id'
))
return
;
// Exclude root
root
.
cascadeBy
(
function
(
localF
ile
)
{
if
(
"root"
==
localF
ile
.
get
(
'id'
))
return
;
// Exclude root
var
pathArray
=
f
ile
.
getPathArray
();
var
pathArray
=
localF
ile
.
getPathArray
();
var
purePathArray
=
pathArray
.
slice
(
0
);
var
fileName
=
f
ile
.
get
(
'name'
);
var
fileName
=
localF
ile
.
get
(
'name'
);
pathArray
.
push
(
fileName
);
console
.
log
(
'Connection.sync local: path='
+
pathArray
);
var
type
=
f
ile
.
get
(
'type'
);
var
type
=
localF
ile
.
get
(
'type'
);
switch
(
type
)
{
case
'file'
:
var
remoteFile
Found
=
me
.
filesStore
.
searchUsingPathArray
(
pathArray
);
if
(
!
remoteFile
Found
)
{
var
remoteFile
=
me
.
filesStore
.
searchUsingPathArray
(
pathArray
);
if
(
!
remoteFile
)
{
var
operation
=
Ext
.
create
(
'POSync.model.Operation'
,
{
id
:
'
op_'
+
file
.
get
(
'id
'
),
file_id
:
f
ile
.
get
(
'id'
),
id
:
'
upload_'
+
pathArray
.
join
(
'_
'
),
file_id
:
localF
ile
.
get
(
'id'
),
file_path
:
purePathArray
.
join
(
'/'
),
file_name
:
f
ile
.
get
(
'name'
),
mime_type
:
f
ile
.
get
(
'mime_type'
),
file_name
:
localF
ile
.
get
(
'name'
),
mime_type
:
localF
ile
.
get
(
'mime_type'
),
file_sha1
:
null
,
local_file
:
localFile
,
remote_file
:
remoteFile
,
op
:
'upload'
});
me
.
operationsStore
.
add
(
operation
);
console
.
log
(
'Connection.sync local: upload: localFile='
+
pathArray
.
join
(
'/'
));
}
else
{
// We already call syncFileLocalRemote with remote files above
// me.syncFileLocalRemote(localFile, remoteFile);
}
break
;
case
'folder'
:
var
remoteFile
Found
=
me
.
filesStore
.
searchUsingPathArray
(
purePathArray
);
if
(
!
remoteFile
Found
)
{
var
remoteFile
=
me
.
filesStore
.
searchUsingPathArray
(
purePathArray
);
if
(
!
remoteFile
)
{
var
operation
=
Ext
.
create
(
'POSync.model.Operation'
,
{
id
:
'
op_'
+
file
.
get
(
'id
'
),
id
:
'
mkdir_'
+
pathArray
.
join
(
'_
'
),
file_id
:
file
.
get
(
'id'
),
file_path
:
purePathArray
.
join
(
'/'
),
file_name
:
file
.
get
(
'name'
),
local_file
:
localFile
,
remote_file
:
remoteFile
,
op
:
'mkdir'
});
me
.
operationsStore
.
add
(
operation
);
console
.
log
(
'Connection.sync local: mkdir: path='
+
purePathArray
.
join
(
'/'
));
}
break
;
default
:
alert
(
'sync: invalid type for local file: '
+
type
);
...
...
@@ -339,6 +365,46 @@ Ext.define('POSync.controller.Connection', {
me
.
syncExecOperations
(
projectId
);
},
/**
* Handles the case that a file is available both locally
* and remotely.
* Checks for creation_date, file_length and compares them
* against the version history of the file on the server.
*/
syncFileLocalRemote
:
function
(
projectId
,
localFile
,
remoteFile
)
{
var
me
=
this
;
console
.
log
(
'Connection.syncFileLocalRemote: local='
+
localFile
.
get
(
'name'
)
+
', '
+
remoteFile
.
get
(
'name'
));
var
configData
=
this
.
guiController
.
configData
;
var
project
=
me
.
projectsStore
.
getById
(
''
+
projectId
);
var
projectPath
=
configData
.
topdir
+
'/'
+
project
.
get
(
'project_path'
);
var
localPathArray
=
localFile
.
getPathArray
();
var
fileName
=
localFile
.
get
(
'name'
);
localPathArray
.
push
(
fileName
);
var
localFullPath
=
projectPath
+
'/'
+
localPathArray
.
join
(
'/'
);
// Check that meta information is available with the local file
var
fs
=
require
(
'fs'
);
var
local_creation_date
=
localFile
.
get
(
'creation_date'
);
if
(
""
===
local_creation_date
)
{
var
stats
=
fs
.
statSync
(
localFullPath
);
localFile
.
set
(
'creation_date'
,
me
.
timeToIso
(
stats
.
birthtimeMs
));
localFile
.
set
(
'modification_date'
,
me
.
timeToIso
(
stats
.
mtimeMs
));
localFile
.
set
(
'content_length'
,
stats
.
size
);
}
var
sha1File
=
require
(
'sha1-file'
);
var
sha1
=
sha1File
(
localFullPath
);
localFile
.
set
(
'sha1'
,
sha1
);
console
.
log
(
'Connection.syncFileLocalRemote: finished'
);
},
syncFileLocalRemoteStats
:
function
(
projectId
,
localFile
,
remoteFile
)
{
alert
(
localFile
);
},
/**
* Takes a store with sync "Operations" and executes them.
...
...
@@ -349,10 +415,8 @@ Ext.define('POSync.controller.Connection', {
console
.
log
(
'Connection.syncExecOperations'
);
me
.
operationsStore
.
each
(
function
(
op
)
{
console
.
log
(
'Connection.syncExecOperations: op'
);
console
.
log
(
op
);
var
operation
=
op
.
get
(
'op'
);
console
.
log
(
'Connection.syncExecOperations: op='
+
operation
+
', id='
+
op
.
get
(
'id'
));
switch
(
operation
)
{
case
'download'
:
me
.
syncDownload
(
projectId
,
op
);
...
...
@@ -379,13 +443,13 @@ Ext.define('POSync.controller.Connection', {
*/
syncDownload
:
function
(
projectId
,
op
)
{
var
me
=
this
;
console
.
log
(
'Connection.syncDownload'
);
var
configData
=
this
.
guiController
.
configData
;
var
fileId
=
op
.
get
(
'file_id'
);
var
filePath
=
op
.
get
(
'file_path'
);
var
fileName
=
op
.
get
(
'file_name'
);
var
mimeType
=
op
.
get
(
'mime_type'
);
console
.
log
(
'Connection.syncDownload: path='
+
filePath
+
', name='
+
fileName
);
// Get the project path
var
project
=
this
.
projectsStore
.
getById
(
''
+
projectId
);
...
...
@@ -428,12 +492,13 @@ Ext.define('POSync.controller.Connection', {
*/
syncUpload
:
function
(
projectId
,
op
)
{
var
me
=
this
;
console
.
log
(
'Connection.syncUpload'
);
var
configData
=
this
.
guiController
.
configData
;
var
filePath
=
op
.
get
(
'file_path'
);
var
fileName
=
op
.
get
(
'file_name'
);
var
mimeType
=
op
.
get
(
'mime_type'
);
var
localFile
=
op
.
get
(
'local_file'
);
console
.
log
(
'Connection.syncUpload: path='
+
filePath
+
', name='
+
fileName
);
// Get the project path
var
project
=
this
.
projectsStore
.
getById
(
''
+
projectId
);
...
...
@@ -452,6 +517,9 @@ Ext.define('POSync.controller.Connection', {
var
formData
=
new
FormData
();
formData
.
append
(
'project_id'
,
projectId
);
formData
.
append
(
'path'
,
filePath
);
formData
.
append
(
'creation_date'
,
localFile
.
get
(
'creation_date'
));
formData
.
append
(
'modification_date'
,
localFile
.
get
(
'modification_date'
));
formData
.
append
(
'sha1'
,
localFile
.
get
(
'sha1'
));
// formData.append('upload_file', fileContent);
var
blob
=
new
Blob
([
fileContent
],
{
type
:
mimeType
});
...
...
@@ -481,11 +549,12 @@ Ext.define('POSync.controller.Connection', {
*/
syncMkdir
:
function
(
projectId
,
op
)
{
var
me
=
this
;
console
.
log
(
'Connection.syncMkdir'
);
// POST the file to the mkdir page
var
configData
=
this
.
guiController
.
configData
;
var
filePath
=
op
.
get
(
'file_path'
);
console
.
log
(
'Connection.syncMkdir: path='
+
filePath
);
var
xhr
=
new
XMLHttpRequest
();
var
url
=
configData
.
url
+
'/intranet-rest-fs-openacs/mkdir'
;
var
formData
=
new
FormData
();
...
...
posync/model/File.js
View file @
bef79b00
...
...
@@ -23,7 +23,6 @@ Ext.define('POSync.model.File', {
'content_length'
,
// File length in bytes (empty string for folders)
'creation_date'
,
// Date of first creation
'publish_date'
,
'modification_date'
,
// Date of last modification
'sha1'
,
// sha-1 hash of the content (empty string for folders)
...
...
posync/model/Operation.js
View file @
bef79b00
...
...
@@ -2,8 +2,6 @@
/*
* What should we do during sync?
*/
Ext
.
define
(
'POSync.model.Operation'
,
{
extend
:
'Ext.data.Model'
,
idProperty
:
'id'
,
...
...
@@ -14,6 +12,8 @@ Ext.define('POSync.model.Operation', {
'file_name'
,
'mime_type'
,
'file_sha1'
,
'op'
'op'
,
'local_file'
,
'remote_file'
]
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment