leeseohyeon

빠른 액세스 수정

...@@ -2,6 +2,7 @@ var express = require('express'); ...@@ -2,6 +2,7 @@ var express = require('express');
2 var router = express.Router(); 2 var router = express.Router();
3 3
4 var fs = require('fs'); 4 var fs = require('fs');
5 +var moment = require('moment');
5 6
6 var AWS = require('aws-sdk'); 7 var AWS = require('aws-sdk');
7 AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json"); 8 AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json");
...@@ -19,7 +20,14 @@ router.get('/:name', function (req, res) { ...@@ -19,7 +20,14 @@ router.get('/:name', function (req, res) {
19 20
20 S3.downloadFile3(S3.BUCKET_NAME, user_id, targetFile, function (result, downloadDir) { 21 S3.downloadFile3(S3.BUCKET_NAME, user_id, targetFile, function (result, downloadDir) {
21 if (result) { 22 if (result) {
22 - res.send({ src: downloadDir }) 23 + var sql = 'UPDATE files SET recent_access=(?) WHERE user_id=(?) AND location=(?) AND file_name=(?)';
24 + connection.query(sql, [moment().format(), user_id, curPath, file_name], function(err){
25 + if (err){
26 + res.send({err: 'update error'});
27 + }else{
28 + res.send({ src: downloadDir })
29 + }
30 + })
23 }else{ 31 }else{
24 res.send({ err: 'download error'}) 32 res.send({ err: 'download error'})
25 } 33 }
......
...@@ -43,8 +43,8 @@ router.post('/:name', function(req, res){ ...@@ -43,8 +43,8 @@ router.post('/:name', function(req, res){
43 43
44 S3.coverFile(S3.BUCKET_NAME, user_id, modified_name, targetPath, tempDownloadDir, function (result) { 44 S3.coverFile(S3.BUCKET_NAME, user_id, modified_name, targetPath, tempDownloadDir, function (result) {
45 if (result) { 45 if (result) {
46 - var sql = 'UPDATE files SET file_name=(?), updated=(?) WHERE user_id=(?) AND location=(?) AND file_name=(?)'; 46 + var sql = 'UPDATE files SET file_name=(?), updated=(?), recent_access=(?) WHERE user_id=(?) AND location=(?) AND file_name=(?)';
47 - connection.query(sql, [modified_name, moment().format(), user_id, curPath, file_name], function (err) { 47 + connection.query(sql, [modified_name, moment().format(), moment().format(), user_id, curPath, file_name], function (err) {
48 if (err) { 48 if (err) {
49 console.log(err); 49 console.log(err);
50 res.send({ error: 'update error' }); 50 res.send({ error: 'update error' });
......
...@@ -2,6 +2,7 @@ var express = require('express'); ...@@ -2,6 +2,7 @@ var express = require('express');
2 var router = express.Router(); 2 var router = express.Router();
3 3
4 var formidable = require('formidable'); 4 var formidable = require('formidable');
5 +var moment = require('moment');
5 6
6 var AWS = require('aws-sdk'); 7 var AWS = require('aws-sdk');
7 AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json"); 8 AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json");
...@@ -66,8 +67,8 @@ router.post('/', function (req, res) { ...@@ -66,8 +67,8 @@ router.post('/', function (req, res) {
66 } 67 }
67 } 68 }
68 for (var sourceFile of noErrSourceFiles) { 69 for (var sourceFile of noErrSourceFiles) {
69 - var sql = 'INSERT INTO files (file_name, user_id, location) VALUES (?, ?, ?)'; 70 + var sql = 'INSERT INTO files (file_name, user_id, location, recent_access) VALUES (?, ?, ?, ?)';
70 - connection.query(sql, [sourceFile, user_id, curPath], function (err, result) { 71 + connection.query(sql, [sourceFile, user_id, curPath, moment().format()], function (err, result) {
71 if (err) { 72 if (err) {
72 console.log('insert error'); 73 console.log('insert error');
73 res.send({error: 'insert error'}); 74 res.send({error: 'insert error'});
......
1 { 1 {
2 - "accessKeyId": "ASIAXZL2SWFEYG2GUYVJ", 2 + "accessKeyId": "ASIAZQ5XTMMFYKGWGIQJ",
3 - "secretAccessKey": "ceYvfLs25iiBDfigO7PbP67kJoKswJdfduqROrJt", 3 + "secretAccessKey": "d3ljiFkZ9QhRxCwE99mw3oFMaVa3JRPkMFDKec48",
4 - "sessionToken": "FwoGZXIvYXdzEDMaDGvezwF9kQrAJ+uhfSLDASWFKBk7UNbRzZVEM1eoGJ3E+UI9d4xSpqEDqRYjsOTn5wYIGM3mUCZ8S6/XCnGP5yFz+qv9mBLDf311iP9ajY091OhQ8c2nB6l+JHuRKAz6FhGLrjHtD1AecHtjHOu5dXODU2+9ctvGj7V60KYqjToah5Tvv84EVac/41Les3rtrqcXS/bbmVwv5kDz9K1FJStln4sXZ/foueGHZAkAJQ6LAtIQWg4/reFUcWAi8E0bUjMckmymDQhnVNWcSbgQ+htBYiiPg+P2BTItOqWuZojM5lw32rTv7+PuOaeyHjx3+Vcd4bo3orSJr57P2ZPfmglZNKY7W5aw", 4 + "sessionToken": "FwoGZXIvYXdzEH8aDHT83Ci5/yuYOOCJTyLDAaQaZLTrJaQf7IsZGhY0UEqpHWgOp7j9T+d/WIpoCxVD/GP53RMlVHlFMfCerfkWEVNXWJOkblExYDBTt4QMLzdhONlOQWVONAvhL8agZ6bUS66sHMQ+PlG+CO/Fjj1pLzOXc2g20elUC0+45pdczi8o33UJEACOCW11K5tYzE2lqjrdggOU00VICLNU5HmPYGH/Sku6NG3goo3hKwrCY2m/YhuPB0hP29g/dLpaUum2oy2VXryi1K255d5tontTA8Dbcyj13PP2BTIt5eqJvxyyyNzJCrXfK1LZkA8WCEMbGTasgfkwm5m7yBKrVFMpEdy9gvcXzuva",
5 "region": "us-east-1" 5 "region": "us-east-1"
6 } 6 }
......
...@@ -5,11 +5,11 @@ var router = express.Router(); ...@@ -5,11 +5,11 @@ var router = express.Router();
5 router.get('/', function(req, res){ 5 router.get('/', function(req, res){
6 var user_id = req.query.id; 6 var user_id = req.query.id;
7 7
8 - var sql = 'SELECT * FROM files WHERE updated>date_sub(now(), interval 3 day) AND user_id=(?) ORDER BY updated DESC'; 8 + var sql = 'SELECT * FROM files WHERE recent_access>date_sub(now(), interval 3 day) AND user_id=(?)';
9 connection.query(sql, user_id, function(err, result){ 9 connection.query(sql, user_id, function(err, result){
10 if (err){ 10 if (err){
11 console.log('select error'); 11 console.log('select error');
12 - res.send({error: 'quick error'}) 12 + res.send({error: 'quick error'});
13 }else{ 13 }else{
14 res.send(result); 14 res.send(result);
15 } 15 }
......