zet-lib 1.4.27 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/zAppRouter.js +17 -56
- package/lib/zDropbox.js +39 -0
- package/lib/zRoute.js +8 -12
- package/package.json +1 -1
package/lib/zAppRouter.js
CHANGED
|
@@ -1873,72 +1873,33 @@ router.post(
|
|
|
1873
1873
|
zDropbox.handleTokenRefresh,
|
|
1874
1874
|
async (req, res) => {
|
|
1875
1875
|
let datas = {};
|
|
1876
|
-
const room = res.locals.token;
|
|
1877
|
-
const { fileName, table, field } = req.body;
|
|
1878
|
-
let dir = `/${table}/${field}`;
|
|
1879
|
-
let pathFile = `${dir}/${fileName}`;
|
|
1880
|
-
console.log(pathFile);
|
|
1881
1876
|
try {
|
|
1882
|
-
const
|
|
1883
|
-
|
|
1884
|
-
}
|
|
1885
|
-
let
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
}
|
|
1877
|
+
const room = res.locals.token;
|
|
1878
|
+
const index = req.params.index;
|
|
1879
|
+
const { fileName, table, field } = req.body;
|
|
1880
|
+
let dir = `/${table}/${field}`;
|
|
1881
|
+
let pathFile = `${dir}/${fileName}`;
|
|
1882
|
+
console.log(pathFile);
|
|
1883
|
+
let jsonMessage = await zDropbox.file(fileName, table, field, index);
|
|
1884
|
+
if (jsonMessage.status == 1) {
|
|
1885
|
+
res.json(jsonMessage.datas);
|
|
1886
|
+
} else {
|
|
1892
1887
|
setTimeout(async () => {
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
link = response.result.link;
|
|
1898
|
-
const mockFile = {
|
|
1899
|
-
name: metadata.result.name,
|
|
1900
|
-
id: metadata.result,
|
|
1901
|
-
path: metadata.result.path_display,
|
|
1902
|
-
link: link,
|
|
1903
|
-
isImage: metadata.result.name.match(/\.(jpg|jpeg|png|gif)$/i),
|
|
1904
|
-
size: metadata.result.size,
|
|
1905
|
-
modified: metadata.result.server_modified,
|
|
1906
|
-
accepted: true,
|
|
1907
|
-
index: req.params.index,
|
|
1908
|
-
};
|
|
1909
|
-
//console.log(mockFile)
|
|
1910
|
-
datas = mockFile;
|
|
1911
|
-
res.json(datas);
|
|
1912
|
-
} catch (e) {
|
|
1913
|
-
console.error("Error getting temporary link:", error);
|
|
1888
|
+
jsonMessage = await zDropbox.file(fileName, table, field, index);
|
|
1889
|
+
if (jsonMessage.status == 1) {
|
|
1890
|
+
res.json(jsonMessage.datas);
|
|
1891
|
+
} else {
|
|
1914
1892
|
io.to(room).emit(
|
|
1915
1893
|
"errormessage",
|
|
1916
|
-
`Please reload your browser
|
|
1894
|
+
`Please reload your browser !! Error ${pathFile} not exist in dropbox, `
|
|
1917
1895
|
);
|
|
1918
1896
|
}
|
|
1919
|
-
},
|
|
1897
|
+
}, 4000);
|
|
1920
1898
|
}
|
|
1921
|
-
const mockFile = {
|
|
1922
|
-
name: metadata.result.name,
|
|
1923
|
-
id: metadata.result,
|
|
1924
|
-
path: metadata.result.path_display,
|
|
1925
|
-
link: link,
|
|
1926
|
-
isImage: metadata.result.name.match(/\.(jpg|jpeg|png|gif)$/i),
|
|
1927
|
-
size: metadata.result.size,
|
|
1928
|
-
modified: metadata.result.server_modified,
|
|
1929
|
-
accepted: true,
|
|
1930
|
-
index: req.params.index,
|
|
1931
|
-
};
|
|
1932
|
-
//console.log(mockFile)
|
|
1933
|
-
datas = mockFile;
|
|
1934
1899
|
} catch (e) {
|
|
1935
1900
|
console.log(e);
|
|
1936
|
-
|
|
1937
|
-
"errormessage",
|
|
1938
|
-
`${e.message} Error ${pathFile} not exist in dropbox, Please reload your browser !!`
|
|
1939
|
-
);
|
|
1901
|
+
res.json(datas);
|
|
1940
1902
|
}
|
|
1941
|
-
res.json(datas);
|
|
1942
1903
|
}
|
|
1943
1904
|
);
|
|
1944
1905
|
|
package/lib/zDropbox.js
CHANGED
|
@@ -131,4 +131,43 @@ zDropbox.deleteFolder = async (dir) => {
|
|
|
131
131
|
}
|
|
132
132
|
};
|
|
133
133
|
|
|
134
|
+
zDropbox.file = async (fileName, table, field, index) => {
|
|
135
|
+
let jsonMessage = Util.flashError("Error");
|
|
136
|
+
let datas = {};
|
|
137
|
+
jsonMessage.datas = datas;
|
|
138
|
+
let dir = `/${table}/${field}`;
|
|
139
|
+
let pathFile = `${dir}/${fileName}`;
|
|
140
|
+
try {
|
|
141
|
+
const metadata = await dbx.filesGetMetadata({
|
|
142
|
+
path: pathFile,
|
|
143
|
+
});
|
|
144
|
+
let link = ``;
|
|
145
|
+
try {
|
|
146
|
+
const response = await dbx.filesGetTemporaryLink({
|
|
147
|
+
path: pathFile,
|
|
148
|
+
});
|
|
149
|
+
link = response.result.link;
|
|
150
|
+
const mockFile = {
|
|
151
|
+
name: metadata.result.name,
|
|
152
|
+
id: metadata.result,
|
|
153
|
+
path: metadata.result.path_display,
|
|
154
|
+
link: link,
|
|
155
|
+
isImage: metadata.result.name.match(/\.(jpg|jpeg|png|gif)$/i),
|
|
156
|
+
size: metadata.result.size,
|
|
157
|
+
modified: metadata.result.server_modified,
|
|
158
|
+
accepted: true,
|
|
159
|
+
index: index,
|
|
160
|
+
};
|
|
161
|
+
//console.log(mockFile)
|
|
162
|
+
jsonMessage = Util.jsonSuccess("Success");
|
|
163
|
+
jsonMessage.datas = mockFile;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.log(error);
|
|
166
|
+
}
|
|
167
|
+
} catch (e) {
|
|
168
|
+
console.log(e);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return jsonMessage;
|
|
172
|
+
};
|
|
134
173
|
module.exports = zDropbox;
|
package/lib/zRoute.js
CHANGED
|
@@ -4898,17 +4898,7 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
|
|
|
4898
4898
|
//console.log('has dropbox')
|
|
4899
4899
|
let dir1 = `/${MYMODEL.table}/${key}`;
|
|
4900
4900
|
let dir2 = `/temps/${MYMODEL.table}/${key}/${userId}`;
|
|
4901
|
-
|
|
4902
|
-
await dbx.filesCreateFolderV2({
|
|
4903
|
-
path: dir1,
|
|
4904
|
-
autorename: false,
|
|
4905
|
-
});
|
|
4906
|
-
} catch (error) {
|
|
4907
|
-
if (error.status !== 409) {
|
|
4908
|
-
// 409 means folder already exists
|
|
4909
|
-
//throw error;
|
|
4910
|
-
}
|
|
4911
|
-
}
|
|
4901
|
+
await zDropbox.ensureFolder(dir1);
|
|
4912
4902
|
let name = `dropbox__${userId}__${MYMODEL.table}__${key}__${whereData.id}`;
|
|
4913
4903
|
if (myCache.has(name)) {
|
|
4914
4904
|
let arr = myCache.get(name) || [];
|
|
@@ -4936,11 +4926,17 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
|
|
|
4936
4926
|
const finalPath = metadata.result.path_display;
|
|
4937
4927
|
if (finalPath) {
|
|
4938
4928
|
let newItem = Util.cleanString(time + item);
|
|
4939
|
-
newArr.push(newItem);
|
|
4940
4929
|
movDropboxArr.push({
|
|
4941
4930
|
from_path: `${dir2}/${item}`,
|
|
4931
|
+
from_dir: dir2,
|
|
4942
4932
|
to_path: `${dir1}/${newItem}`,
|
|
4933
|
+
to_dir: dir1,
|
|
4943
4934
|
});
|
|
4935
|
+
newArr.push(newItem);
|
|
4936
|
+
/*movDropboxArr.push({
|
|
4937
|
+
from_path: `${dir2}/${item}`,
|
|
4938
|
+
to_path: `${dir1}/${newItem}`,
|
|
4939
|
+
});*/
|
|
4944
4940
|
}
|
|
4945
4941
|
} catch (e) {
|
|
4946
4942
|
console.log(e);
|