vfd-cloud
A cloud storage web disk project based on SpringBoot, suitable for practicing learning SpringBoot, the technology stack used is listed below. Support user registration login and modify password, using mailbox verification. Upload, download, share and delete files. Support folder creation, sharing and deletion.
- User registration login and password modification, using mailbox verification
- Upload and download files as well as share and delete files
- File classification search
- Folder creation, sharing and deletion
- Remember me when users log in, and log out
- After file sharing, you can view all shared links and link status, and cancel the sharing of a link or cancel all links at any time
Share Link interface
Preview the shared file
Save the shared file
Recycle bin interface
1. Core technology stack
The back-end
- SpringBoot2
- MyBatis
- Redis
- RabbitMQ
- MySQL
The front end
- Html5+Css+JavaScript
- JQuery
- Bootstrap
- Thymeleaf
Ii. Project plan
- Account information management module
- File upload download delete module
- Folder management module
- File encryption decryption processing module
- File sharing module
- Recycle bin and file recovery module
- Administrator to the user management module
- File retrieval module
- Etc. Other modules (to be added later)
1. Account information management module
mysql> desc user_login;
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment | | email | varchar(50) | NO | UNI | NULL | | | password | varchar(50) | NO | | NULL | | | name | varchar(50) | NO | | NULL | | +----------+-------------+------+-----+---------+----------------+
Copy the code
The registration, login and password change of the user account are verified by email. During the registration process, the verification code is sent to the email and stored in Redis, and the validity period is set for a certain period of time. Registration within the validity period is regarded as successful registration. During password change, a UUID used for authentication is stored in Redis, the validity period is set, and a link to change the password is sent to the mailbox. If the UUID in the link is valid and matches the mailbox, the interface for changing the password is provided.
Use message queues for asynchrony to improve efficiency. Both registration and password change involve two processes: saving the authentication information into Redis and sending an email to the user’s email address. Send the two tasks to the message queue asynchronously and then return information to the user.
2. File upload, download and delete module
mysql> desc file;
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(50) | NO | | NULL | | | len | int(11) | NO | | NULL | | | pid | int(11) | NO | PRI | NULL | | | location | varchar(50) | NO | | NULL | | | type | int(11) | NO | | NULL | | | time | datetime | YES | | NULL | | +----------+-------------+------+-----+---------+----------------+
Copy the code
The management of files uses mysql to store information, and later plans to add a non-relational database to store some information. Select * from file where fid = ${id}; select * from file where fid = ${id}; In addition, the data table of the file also has the file ID, name, size, upload time, storage address and so on.
When uploading a file, make an asynchronous request with Ajax, and use the callback function to get the number of bytes uploaded and the total number of bytes, so that you can monitor the upload progress. After the file is uploaded, you only need to asynchronously refresh the contents of the current folder to display the effect in real time.
When downloading a file, add content-lenght to the response header so that the browser can track the progress of the file download.
In order to ensure the efficiency of file deletion, that is, not to let users wait too long, as long as the record is deleted in the database, the deletion succeeds. Then use an asynchronous task to actually delete the files on disk so that the user is guaranteed quick feedback. In addition, set a scheduled task to periodically check the correspondence between the database and the files on the disk. If there are isolated files (files that are not recorded in the database), delete them.
3. Folder management module
Each file has a parent directory ID attribute, which represents the ID of the folder in which it is located. In this way, you can find all files and folders under its directory by the ID of a folder.
The logic for creating a folder is similar to uploading a file, but without the file transfer process, you only need to add the corresponding record to the database.
When deleting a folder, pay attention to the recursive deletion of all contents in this folder. When the user initiates the deletion request, the record of this folder will be deleted in the database. And its subdirectories child files are asynchronous task to complete, so that we can guarantee the efficiency, and at the same time in order to correct, you can add tasks regularly, to check the corresponding relationship of the database and disk regularly, and whether there are isolated directory (isolated directory refers to the file or folder can’t find the parent directory), if you have just delete them.
4. File encryption module
Sm4 algorithm is used to encrypt and decrypt the files. When uploading the files, the files are uploaded to the server and stored in ciphertext form, so that the file content does not have to worry about leakage. During the download, you need to download the plaintext file to the local computer, decrypt the file to a temporary folder, and store the decrypted file in it. When the download is complete, you can delete the decrypted ciphertext using an asynchronous task.
5. File sharing module
When sharing a file, generate a random UUID. Store the random UUID in Redis according to the set sharing deadline, set the expiration time, use userAccount :share:UUID as the key, and use the information about the shared file and its subfiles as the value. It is stored in REDis in the form of JSON. When someone wants to get the shared file, they can get all the file information they need to get according to JSON. They only need to add corresponding records in the database.
6. Recycle bin module
File can be temporarily stored in first (delete) is not really in the recycle bin, the realization of the function of the thinking and some similar to share files, and will join the recycle bin file information is removed from the mysql database, but it doesn’t actually delete a file on disk, then this information in to redis and set the expiration time, This allows it to be restored to mysql within the validity period based on information in Redis. It can be restored to its original location within the default finite period of time, but there is also the problem of path conflict, which gives two choices: renaming and overwriting.
7. File retrieval module
Plan to tag files and then retrieve them based on tag, filename, and so on
Third, write at the end
The basic functions of the project are completed. Welcome to visit the project warehouse, if you like, I hope you can point a star!! Progress together! The remaining modules will be developed as planned.