This article is suitable for people who have basic knowledge of Java. You can learn and run Java web disk projects with this article.


Author: HelloGitHub- Qin Ren

HelloGitHub introduces the Open Source project series.

Today to bring you an open source Java version of the web disk project — KIFTD-Source, this article will use 3 minutes to take you to build a personal web disk, technology convenient life, you deserve to have ~

The address of the project: https://github.com/KOHGYLW/kiftd-source

I. Project introduction

Kiftd is an open source, easy to use, complete Java web disk/cloud disk system. A file cloud storage platform that supports functions such as online video playback, online document preview, music playback, and image viewing.

Technology stack

  • JDK version: 1.8.0_131
  • Maven (M2E 1.8.0 for Eclipse)
  • Archetype: mavem Archetype – quickstart 1.1
  • SpringBoot: SpringBoot is based on Spring and is designed to improve the development efficiency of microservices.
  • MyBatis: an excellent persistence layer framework that supports custom SQL, stored procedures, and advanced mapping.
  • H2 DB: An open source embedded database engine written in The Java language, platform-independent.

Two, network disk construction

2.1 Running in Windows

2.1.1 Downloading the installation package

Directly from the website to download the latest installation package, the installation address: https://kohgylw.gitee.io/

The project is cozy and supports three download methods: Github, Aliyun and Gitee. The diagram below:


2.1.2 Checking the Configuration

To check whether the local JDK is installed, run the Java -version command on the CLI to check the Java version. If you have installed it, as shown below, you can proceed to the next step.

java version "1.8.0 comes with _181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
Copy the code

2.1.3 run the jar

Jar, or run the Java -jar kiftd-1.0.29-release. jar command from the command line to run the JAR file, and the installation interface will pop up, as shown in the following figure:


The buttons in this interface illustrate:

  • Start: Starts the web disk service. The default port for starting the web disk service is Start8080.
  • Files: This button menu mainly has web disk file import, export, delete, refresh functions.
  • Setting: Sets the service port and physical storage path of a web disk.
  • Exit: Shuts down the web disk system.

Click the “Start” button to run the web disk. The port I set here is 8090, and then visit: localhost:8090 in the browser. The running effect is as follows:


Is the project running, found a problem cannot upload files? Because we forgot to log in. Click the system login button, fill in the account number and password to log in. So where’s the login password? The user information is in conf/account.properties.

#<This is the default kiftd account setting file. >
#Sun May 10 21:56:28 CST 2020
admin.pwd=000000  # username.password =000000
authOverall=l
admin.auth=cudrm
Copy the code
  • User name: admin
  • Password: 000000

In this way, you can use all the functions of the web disk after logging in.

2.2 Running in Linux

2.2.1 Installing Screen

The Screen tool can virtualize a terminal and perform operations accordingly. Because the network disk that this tells needs a terminal. Run the following command to install Screen:

yum install screen
Copy the code

2.2.2 ScreenCommon commands

screen -S myScreen Create a virtual terminal
Java - jar kiftd - 1.0.29 - the jar - the console# Start kIFTD in command mode in virtual terminal
screen -r myScreen Return to the previous virtual terminal and continue with kifTD.
Copy the code

2.2.3 CLI Operations

Starting in console mode on Linux looks like this:


To run the project, enter -start on the command line. For example, enter -files and the console will look like this:


In fact, the same as Windows, including file import, export, delete function, more than a few commands is to view files, switch directories and other functions.

Iii. Development environment operation

3.1 Downloading Items

There are two ways to download a project, using GitBash to download a project:

git clone https://github.com/KOHGYLW/kiftd-source.git
Copy the code

Another way to directly download the ZIP package is as follows:


3.2 run

Open the kohgylw.kiftd.mc.mc class and run the test. Note: This article opens using Eclipse tools.


3.3 Read the Code

3.3.1 Foreground Request

Take creating a directory as an example. Let’s look at the front end first. Click “Operation” -> “New Folder”, fill in the folder name, and click save as shown below:


We know that the background interface for the foreground newFolder function call is newfolder.ajax

3.3.2 rainfall distribution on 10-12 backend interface By the front desk requests call whether the backend interface for homeController/newFolder ajax. When we open the code implementation, we see the following method.

public String newFolder(final HttpServletRequest request) {
  
.        // Some code for parameter verification has been omitted
  Folder f = new Folder();
 f.setFolderId(UUID.randomUUID().toString());  f.setFolderName(folderName);  f.setFolderCreationDate(ServerTimeUtil.accurateToDay());  if(account ! =null) {  f.setFolderCreator(account);  } else {  f.setFolderCreator(Anonymous User);  }  f.setFolderParent(parentId);  int i = 0;  while (true) {  try {  // The database inserts the data in the newly created folder  final int r = this.fm.insertNewFolder(f);  if (r > 0) {  if (fu.isValidFolder(f)) {  this.lu.writeCreateFolderEvent(request, f);  return "createFolderSuccess";  } else {  return "cannotCreateFolder";  }  }  break;  } catch (Exception e) {  f.setFolderId(UUID.randomUUID().toString());  i++;  }  if (i >= 10) {  break;  }  }  return "cannotCreateFolder";  } Copy the code

Iv. Function Description

4.1 upload

  1. Click on theoperation, you can upload files and folders, as shown below:

  2. You can also upload the file by dragging the web disk page.

4.2 Video/Audio Playback

  1. Upload videos to the web disk. The web disk also supports online video playback. The effect is as follows:

  2. Upload audio, such as my favoriteJay ChouSongs can now be played online.

4.3 Using Shortcut Keys

The web disk also adds shortcut keys to some common functions. The functions and shortcuts are as follows:

function shortcuts
Upload folders Shift +U
Upload a file Shift +F
The new file Shift +N
copy Shift +C
shear Shift +X
delete Shift +D

4.4 Modifying configuration Files

Configuration files in the project conf directory include two configuration files:

  • account.properties: Configures account information and permission information
  • server.properties: Configuration file of the server, which can configure the server port, buffer file size, etc

4.5 Online Preview

The web disk supports online preview of TXT, PDF, DOCX, and PPT documents, and online preview of pictures. The preview effect is as follows:


The preview effect of the PDF file is as follows:


4.6 Sharing download Links

Web disk also considers file sharing, it can generate download link, browser access download link can directly download files. Select the file to download, click the download button, select download link +, you can generate the file download link. The diagram below:


Five, the last

That’s the end of the tutorial. Is your own disk up and running? Net disk is not bad? And it’s incredibly easy to set up. Some important things can be stored in their own network disk! At the end of the day, a programming language is just a tool, and as long as we use the tools well, with our own unconstrained thinking, I think we can create more incredible projects.

The reason for the longevity of the Java language is that it can do so much, and its ecology is incredibly rich. If you are also interested, join the family of Javaer developers! Open source sharing allows us to get to know each other, and having open source projects allows us to see the beauty of programming languages.

Tutorial at this point, you should also be able to quickly run personal web disk. Is programming particularly fun? Download the installation package and deploy a web disk system for yourself. Interested in source code friends can start learning project source ~


Pay attention to the public account to join the communication group