Answered by Borut | Apr. 11, 2023 00:01
Your both itineraries are eligible for 24 or 144 hours visa free transit, so you don't need any kind of visa.
Whether you will use 24 or 144 hours visa free transit option will depend on the length of your stay in Shanghai area. So, if your entire stay in Shanghai area is less than 24 hours, you will be eligible for 24 hours visa free transit and if your stay exceeds 24 hours, you will use 144 hours visa free transit.
It is important that your flights do not have any additional landings within mainland China beside Shanghai, of course.
Once again, you will travel visa free and there will be no visas of any kind required in your case.