Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chat
RocketChatMobileEngine
Commits
4de277b7
Commit
4de277b7
authored
Feb 27, 2019
by
armin
Browse files
fix fileupload on android
parent
4a59d1e9
Changes
2
Hide whitespace changes
Inline
Side-by-side
fileuploader.cpp
View file @
4de277b7
...
...
@@ -25,7 +25,11 @@
FileUploader
::
FileUploader
(
QObject
*
parent
,
RocketChatServerData
*
pServer
,
const
QUrl
&
pUri
,
const
QString
&
pChannelId
)
:
QObject
(
parent
),
mUri
(
pUri
),
mChannelId
(
pChannelId
),
mServer
(
pServer
)
{
#ifdef Q_OS_ANDROID
auto
file
=
QSharedPointer
<
QFile
>::
create
(
pUri
.
path
()
);
#else
auto
file
=
QSharedPointer
<
QFile
>::
create
(
pUri
.
toLocalFile
()
);
#endif
if
(
file
->
isOpen
()
)
{
file
->
close
();
...
...
@@ -195,12 +199,14 @@ void FileUploader::nextRequest()
auto
request
=
mPartialRequests
.
first
();
double
diff
=
request
->
getProgress
()
-
progress
;
uint
now
=
QDateTime
::
currentDateTime
().
toTime_t
();
if
(
diff
>=
0.05
&&
now
-
lastUpdate
){
if
(
diff
>=
0.05
&&
now
-
lastUpdate
)
{
progress
=
request
->
getProgress
();
qDebug
()
<<
"progress is "
<<
progress
;
qDebug
()
<<
"progress is "
<<
progress
;
emit
progressChanged
(
progress
);
lastUpdate
=
now
;
}
mServer
->
sendApiRequest
(
request
,
true
);
}
}
...
...
services/fileservice.cpp
View file @
4de277b7
...
...
@@ -70,74 +70,74 @@ FileService::FileService( RocketChatServerData *server )
*/
bool
FileService
::
getFileRessource
(
const
QSharedPointer
<
FileRequest
>
&
pRequest
)
{
if
(
mServer
)
{
auto
repo
=
mServer
->
getFiles
();
if
(
mServer
)
{
auto
repo
=
mServer
->
getFiles
();
if
(
!
pRequest
.
isNull
()
&&
pRequest
->
url
.
size
()
>
0
)
{
if
(
mCurrentDownloads
.
contains
(
pRequest
->
url
)
)
{
return
true
;
}
if
(
!
pRequest
.
isNull
()
&&
pRequest
->
url
.
size
()
>
0
)
{
if
(
mCurrentDownloads
.
contains
(
pRequest
->
url
)
)
{
return
true
;
}
auto
tempFile
=
getFileFromCache
(
pRequest
);
auto
tempFile
=
getFileFromCache
(
pRequest
);
if
(
!
tempFile
.
isNull
()
)
{
if
(
!
tempFile
.
isNull
()
)
{
if
(
!
pRequest
->
showInline
)
{
auto
location
=
determineLocation
(
pRequest
->
url
,
pRequest
->
type
,
false
);
QFile
targetFile
(
location
);
if
(
!
pRequest
->
showInline
)
{
auto
location
=
determineLocation
(
pRequest
->
url
,
pRequest
->
type
,
false
);
QFile
targetFile
(
location
);
if
(
targetFile
.
exists
()
)
{
auto
parts
=
location
.
split
(
"."
);
location
.
clear
();
if
(
targetFile
.
exists
()
)
{
auto
parts
=
location
.
split
(
"."
);
location
.
clear
();
for
(
auto
i
=
0
;
i
<
(
parts
.
length
()
-
1
);
i
++
)
{
location
+=
parts
[
i
];
for
(
auto
i
=
0
;
i
<
(
parts
.
length
()
-
1
);
i
++
)
{
location
+=
parts
[
i
];
if
(
i
<
(
parts
.
length
()
-
1
)
)
{
location
+=
QStringLiteral
(
"."
);
if
(
i
<
(
parts
.
length
()
-
1
)
)
{
location
+=
QStringLiteral
(
"."
);
}
}
}
location
+=
QStringLiteral
(
"_"
)
+
QString
::
number
(
QDateTime
::
currentSecsSinceEpoch
()
);
location
+=
QStringLiteral
(
"."
)
+
parts
[
parts
.
size
()
-
1
];
location
+=
QStringLiteral
(
"_"
)
+
QString
::
number
(
QDateTime
::
currentSecsSinceEpoch
()
);
location
+=
QStringLiteral
(
"."
)
+
parts
[
parts
.
size
()
-
1
];
QFile
oldFile
(
tempFile
->
getFilePath
()
);
QFile
oldFile
(
tempFile
->
getFilePath
()
);
if
(
oldFile
.
copy
(
location
)
)
{
tempFile
=
QSharedPointer
<
TempFile
>::
create
(
location
,
pRequest
->
url
);
}
else
{
qWarning
()
<<
oldFile
.
errorString
();
}
}
else
{
QFile
oldFile
(
tempFile
->
getFilePath
()
);
QString
path
=
location
;
QStringList
pathParts
=
location
.
split
(
"/"
);
pathParts
.
removeLast
();
QString
dirStr
=
pathParts
.
join
(
"/"
);
QDir
dir
;
if
(
dir
.
mkpath
(
dirStr
)
)
{
if
(
oldFile
.
copy
(
location
)
)
{
tempFile
=
QSharedPointer
<
TempFile
>::
create
(
location
,
pRequest
->
url
);
}
else
{
qWarning
()
<<
oldFile
.
errorString
();
}
}
else
{
qWarning
()
<<
"could not create: "
<<
dirStr
;
QFile
oldFile
(
tempFile
->
getFilePath
()
);
QString
path
=
location
;
QStringList
pathParts
=
location
.
split
(
"/"
);
pathParts
.
removeLast
();
QString
dirStr
=
pathParts
.
join
(
"/"
);
QDir
dir
;
if
(
dir
.
mkpath
(
dirStr
)
)
{
if
(
oldFile
.
copy
(
location
)
)
{
tempFile
=
QSharedPointer
<
TempFile
>::
create
(
location
,
pRequest
->
url
);
}
else
{
qWarning
()
<<
oldFile
.
errorString
();
}
}
else
{
qWarning
()
<<
"could not create: "
<<
dirStr
;
}
}
}
}
pRequest
->
then
(
tempFile
,
pRequest
->
showInline
);
}
else
{
getFileFromServer
(
pRequest
);
}
pRequest
->
then
(
tempFile
,
pRequest
->
showInline
);
}
else
{
getFileFromServer
(
pRequest
);
}
}
}
return
false
;
...
...
@@ -145,7 +145,7 @@ bool FileService::getFileRessource( const QSharedPointer< FileRequest > &pReques
void
FileService
::
getFilesFromDb
()
{
if
(
mServer
)
{
if
(
mServer
)
{
auto
files
=
mStorage
->
getFiles
();
auto
repo
=
mServer
->
getFiles
();
...
...
@@ -159,7 +159,7 @@ void FileService::getFilesFromDb()
QSharedPointer
<
TempFile
>
FileService
::
getFileFromCache
(
const
QSharedPointer
<
FileRequest
>
&
pRequest
)
{
if
(
!
pRequest
.
isNull
()
&&
mServer
)
{
if
(
!
pRequest
.
isNull
()
&&
mServer
)
{
auto
repo
=
mServer
->
getFiles
();
if
(
repo
==
nullptr
)
{
...
...
@@ -170,10 +170,6 @@ QSharedPointer<TempFile> FileService::getFileFromCache( const QSharedPointer< Fi
QString
fullUrl
=
baseUrl
+
pRequest
->
url
;
qDebug
()
<<
"file from cache requested"
<<
fullUrl
;
if
(
fullUrl
.
contains
(
"ras"
)){
qDebug
()
<<
"ras found"
;
}
if
(
repo
->
contains
(
fullUrl
)
)
{
auto
storageEntry
=
repo
->
get
(
fullUrl
);
...
...
@@ -184,15 +180,16 @@ QSharedPointer<TempFile> FileService::getFileFromCache( const QSharedPointer< Fi
}
if
(
storageEntry
->
getFileChecked
()
)
{
if
(
storageEntry
->
getFileChecked
()
)
{
return
storageEntry
;
}
else
{
QFile
cacheHit
(
storageEntry
->
getFilePath
()
);
if
(
cacheHit
.
exists
()){
storageEntry
->
setFileChecked
(
true
);
return
storageEntry
;
}
}
}
else
{
QFile
cacheHit
(
storageEntry
->
getFilePath
()
);
if
(
cacheHit
.
exists
()
)
{
storageEntry
->
setFileChecked
(
true
);
return
storageEntry
;
}
}
mStorage
->
removeFileCacheEntry
(
pRequest
->
url
,
storageEntry
->
getFilePath
()
);
repo
->
remove
(
fullUrl
);
...
...
@@ -209,7 +206,7 @@ QSharedPointer<TempFile> FileService::getFileFromCache( const QSharedPointer< Fi
void
FileService
::
getFileFromServer
(
const
QSharedPointer
<
FileRequest
>
&
pRequest
)
{
if
(
Q_LIKELY
(
!
pRequest
.
isNull
()
&&
mServer
)
)
{
if
(
Q_LIKELY
(
!
pRequest
.
isNull
()
&&
mServer
)
)
{
auto
baseUrl
=
mServer
->
getRestApi
()
->
getBaseUrl
();
auto
fullUrl
=
baseUrl
+
pRequest
->
url
;
...
...
@@ -356,7 +353,7 @@ QString FileService::determineLocation( const QUrl &pUrl, const QString &pType,
filePath
=
mMusicPath
+
urlPath
;
}
else
if
(
pType
==
"document"
)
{
filePath
=
mDocumentPath
+
urlPath
;
}
else
{
}
else
{
filePath
=
mTempPath
+
urlPath
;
}
}
else
{
...
...
Write
Preview
Supports
Markdown
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